1、实例demo是用谷歌浏览器在百度首页搜python的动作脚本;

      BaiDu_test是指脚本中自己定义的类名,test_get是指你的类中定义的testcase方法。

   在if name函数下加入testcase时,python3.6版本的方法是 

suiter = addtest(类名('测试方法'))

 suiter = addTest(BaiDu_test("test_get"))

from selenium import webdriver
import unittest
import time
from HTMLTestRunner import HTMLTestRunner class BaiDu_test(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.url = "https://www.baidu.com/"
self.driver.implicitly_wait(10)
self.driver.maximize_window() def test_get(self):
driver = self.driver
driver.get(self.url)
print("当前网址"+driver.current_url)
time.sleep(5)
driver.find_element_by_id("kw").send_keys("python")
time.sleep(2)
driver.find_element_by_id("su").click() def tardown(self):
#清除缓存
self.driver.refresh()
self.driver.quit() if __name__ == "__main__":
suite = unittest.TestSuite()
suite.addTest(BaiDu_test('test_get'))
sop = open(r'D:\test_02.html','wb')
runner = HTMLTestRunner(stream=sop,
title="asd",
description='asdasd')
runner.run(suite)

2、在python3.7版本中是以引用方法加入用例

suiter =  addtest(类名 . 测试方法())

                           suiter = addTest(myclass.testcase())

from selenium import webdriver
import unittest
import time
from HTMLTestRunner import HTMLTestRunner class BaiDu_test(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.url = "https://www.baidu.com/"
self.driver.implicitly_wait(10)
self.driver.maximize_window() def test_get(self):
driver = self.driver
driver.get(self.url)
print("当前网址"+driver.current_url)
time.sleep(5)
driver.find_element_by_id("kw").send_keys("python")
time.sleep(2)
driver.find_element_by_id("su").click() def tardown(self):
#清除缓存
self.driver.refresh()
self.driver.quit() if __name__ == "__main__":
suite = unittest.TestSuite()
suite.addTest(BaiDu_test.test_get())
sop = open(r'D:\test_02.html','wb')
runner = HTMLTestRunner(stream=sop,
title="asd",
description='asdasd')
runner.run(suite)

Python3.7版本unittest框架添加用例的方法的更多相关文章

  1. unittest框架里的常用断言方法:用于检查数据

    1.unittest框架里的常用断言方法:用于检查数据. (1)assertEqual(x,y) 检查两个参数类型相同并且值相等.(2)assertTrue(x) 检查唯一的参数值等于True(3)a ...

  2. Python3 完美解决unittest框架下不生成测试报告

    前提: 1.运行测试用例一切正常,只是没有测试报告显示 2.使用命令行pyhon 脚本名字.py 却可以生成测试报告 3.pycharm 在运行测试用例的时候 默认是以unittest 框架来运行的, ...

  3. python unittest 框架添加测试用例及运行

    找出要测试的testcase,并加入到Testsuite,运行Testsuite并把结果给TestResult1.创建TestSuite实例对象suite = unittest.TestSuite() ...

  4. python3 unittest框架失败重跑加截图支持python2,python3

    github源码地址下载:https://github.com/GoverSky/HTMLTestRunner_cn.git 解压文件后取出/HTMLTestRunner_cn.py文件丢进C:\Py ...

  5. unittest框架(一)用例管理

    在unittest框架的自动化接口测试中,可以用yaml文件来管理用例,这样一方面,不会像excel管理用例那么死板:另一方面,数据读取出来就是一个字典,便于取值,用起来更灵活. 首先,需要安装一个模 ...

  6. 基于python3在nose测试框架的基础上添加测试数据驱动工具

    [本文出自天外归云的博客园] Python3下一些nose插件经过2to3的转换后失效了 Python的nose测试框架是通过python2编写的,通过pip3install的方式安装的nose和相关 ...

  7. 【python3+request】python3+requests接口自动化测试框架实例详解教程

    转自:https://my.oschina.net/u/3041656/blog/820023 [python3+request]python3+requests接口自动化测试框架实例详解教程 前段时 ...

  8. 第9课:备份mysql数据库、重写父类、unittest框架、多线程

    1. 写代码备份mysql数据库: 1)Linux下,备份mysql数据库,在shell下执行命令:mysqldump -uroot -p123456 -A >db_bak.sql即可 impo ...

  9. selenium自动化测试、Python单元测试unittest框架以及测试报告和日志输出

    部分内容来自:https://www.cnblogs.com/klb561/p/8858122.html 一.基础介绍 核心概念:test case, testsuite, TestLoder,Tex ...

随机推荐

  1. 读取文件不是真实的具体路径 setZh.ini

    读取 c:\windows\Syswow64\XX\XX.ini 时内容不正确. 发现真实文件为: C:\Users\用户名\AppData\Local\VirtualStore\Windows\Sy ...

  2. 吴裕雄 python 机器学习——ElasticNet回归

    import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot ...

  3. Windows下javac不可用,java -version可以

    https://blog.csdn.net/kobedir/article/details/79709287

  4. k8s 代码生成

    https://blog.openshift.com/kubernetes-deep-dive-code-generation-customresources/ # 代码生成的工作目录,也就是我们的项 ...

  5. js,jquery备忘录

    1.var s = str.charCodeAt();转ASCII码 2.String.fromCharCode(65);转字母 3.es6 ... (扩展运算符),将一个数组转化成由逗号分割的队列. ...

  6. Unity中建立文本保存数据

    public void CreateYunYD() { GameToolsManager.Instance.effectType = EFFECTTYPE.YunYD; CreateYunOrWu(& ...

  7. Jmeter Dash Report(HTML Report)删除Hits Per Second graph的方法

    通过命令行 Non GUI的方式执行jmeter的jmx脚本可以生成HTML Report(Dash Report). 这个report默认自带了很多种图表报告,比如statistics,Over t ...

  8. 【java】多个对象的序列化和反序列化

    当我们需要序列化多个对象的时候,可以采用集合把多个对象放到集合中,然后序列化整个集合. 而我们要反序列化的时候,就使用集合接收反序列化后的对象 如: List<Student> stude ...

  9. JS解决在提交form表单时某个值不存在 alter弹窗点确定不刷新界面

    <form action="" method="post" onsubmit="return checkname()"> < ...

  10. intelliJ idea如何安装、配置

    https://www.cnblogs.com/jajian/p/7989032.html