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. 吴裕雄 python matplotlib 绘图示例

    import matplotlib.pyplot as plt plt.scatter([1,2,3,4],[2,3,2,5])plt.title('My first plot')plt.show() ...

  2. layui-xtree 设置单选框,只能选一个

    以下是js代码,首先获取所有节点,再设置只有当前点击的节点状态为选中状态 $.ajax({ type: 'get', url: url, error: function(err){ layer.ale ...

  3. UGUI脚本添加Btn回调的方法

    using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; ...

  4. Mysql优化策略

    总的来说:1.数据库设计和表创建时就要考虑性能 2.sql的编写需要注意优化 3.分区.分表.分库 设计表的时候: 1.字段避免null值出现,null值很难查询优化且占用额外的索引空间,推荐默认数字 ...

  5. python3 BeautifulSoup模块

    一.安装下载: 1.安装: pip install beautifulsoup4 2.可选择安装解析器:pip install lxmlpip install html5lib 3.解析器比较: 解析 ...

  6. vue的表单输入绑定

    1.单行绑定 <p>{{logintype}}</p> <input type="text" v-model="logintype" ...

  7. 关于easyui框架中a标签使用onclick()触发事件偶尔会选项卡消失BUG解决方案

    今天发现公司的一个easyui项目中有个页面会在触发onclick事件时选项卡消失,如下图 产生BUG后 产生BUG前 查找很多地方还有资料不知道哪里出现的问题,看了下框架源码之类的,因为不是专门的前 ...

  8. 把Excel作为数据库,读到DataTable中,Excel科学计数法数字转字符串

    需要引用:using System.Data.OleDb; /// <summary> /// 获取Excel数据,包含所有sheet /// </summary> /// & ...

  9. js实现动态加载脚本的方法实例汇总

      本文实例讲述了js实现动态加载脚本的方法.分享给大家供大家参考,具体如下: 最近公司的前端地图产品需要做一下模块划分,希望用户用到哪一块的功能再加载哪一块的模块,这样可以提高用户体验. 所以到处查 ...

  10. 人脸识别1:n对比 (二)

    本项目采用了百度AI 人脸识别 第三方接口,实现了自选本地手机相册图片上传人脸(faceSet中添加人脸) 和 自选本地手机相册图片寻找出集合中相似度最高的一个face,可返回比对相似度.位置等信息. ...