Python3.7版本unittest框架添加用例的方法
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框架添加用例的方法的更多相关文章
- unittest框架里的常用断言方法:用于检查数据
1.unittest框架里的常用断言方法:用于检查数据. (1)assertEqual(x,y) 检查两个参数类型相同并且值相等.(2)assertTrue(x) 检查唯一的参数值等于True(3)a ...
- Python3 完美解决unittest框架下不生成测试报告
前提: 1.运行测试用例一切正常,只是没有测试报告显示 2.使用命令行pyhon 脚本名字.py 却可以生成测试报告 3.pycharm 在运行测试用例的时候 默认是以unittest 框架来运行的, ...
- python unittest 框架添加测试用例及运行
找出要测试的testcase,并加入到Testsuite,运行Testsuite并把结果给TestResult1.创建TestSuite实例对象suite = unittest.TestSuite() ...
- python3 unittest框架失败重跑加截图支持python2,python3
github源码地址下载:https://github.com/GoverSky/HTMLTestRunner_cn.git 解压文件后取出/HTMLTestRunner_cn.py文件丢进C:\Py ...
- unittest框架(一)用例管理
在unittest框架的自动化接口测试中,可以用yaml文件来管理用例,这样一方面,不会像excel管理用例那么死板:另一方面,数据读取出来就是一个字典,便于取值,用起来更灵活. 首先,需要安装一个模 ...
- 基于python3在nose测试框架的基础上添加测试数据驱动工具
[本文出自天外归云的博客园] Python3下一些nose插件经过2to3的转换后失效了 Python的nose测试框架是通过python2编写的,通过pip3install的方式安装的nose和相关 ...
- 【python3+request】python3+requests接口自动化测试框架实例详解教程
转自:https://my.oschina.net/u/3041656/blog/820023 [python3+request]python3+requests接口自动化测试框架实例详解教程 前段时 ...
- 第9课:备份mysql数据库、重写父类、unittest框架、多线程
1. 写代码备份mysql数据库: 1)Linux下,备份mysql数据库,在shell下执行命令:mysqldump -uroot -p123456 -A >db_bak.sql即可 impo ...
- selenium自动化测试、Python单元测试unittest框架以及测试报告和日志输出
部分内容来自:https://www.cnblogs.com/klb561/p/8858122.html 一.基础介绍 核心概念:test case, testsuite, TestLoder,Tex ...
随机推荐
- 《Dare To Dream》第七次作业:团队项目设计完善&编码测试
任务一:团队项目<软件设计方案说明书>Github链接:https://github.com/Sophur/Team-Project 任务二:项目集成开发环境: (1)JSP技术 JSP( ...
- 关于导入zepto出错的问题
一.前言 webpack在配置多页面开发的时候 ,发现用 import 导入 Zepto 时,会报 Uncaught TypeError: Cannot read property 'createEl ...
- mysql访问视图提示:找不到视图
原因: 1.不存在 2.视图区分大小写(有的不区分) 3.权限问题
- intellij idea在project下同时打开多个工程(maven工程)
前提:我的工程都是maven工程 我有两个工程,一个是接口contract,一个是接口的具体实现server.想要同时在一个工作空间下展示,方便调试开发,加载后效果如下 idea有worksp ...
- Angularjs 滚动条控制
控制滚动条 依赖 $location, $anchorScroll $scope.gotoTop = function () { $location.hash("top"); $a ...
- Appium+python自动化获取toast消息的方法
转载地址:https://www.cnblogs.com/shangren/p/8191879.html 1. 首先执行这个命令:npm install -g cnpm --registry=http ...
- 记忆化搜索 P1464 Function
题目描述 对于一个递归函数w(a,b,c) 如果a≤0 or b≤0 or c≤0就返回值1. 如果a>20 or b>20 or c>20就返回w(20,20,20) 如果a< ...
- OSPFv3综合实验(GNS3)
一.实验目的 1. 掌握 OSPFv3(v2) 的配置方法 2. 掌握在帧中继环境下 OSPFv3 (v2)的配置方法 3. 掌握 OSPFv3(v2) NSSA 的配置方法 4. 掌握外部路 ...
- 监控服务器配置(四)-----OracleDb_exporter安装配置
1.下载oracle客户端安装包(linux版)到 /opt/minitor/oracleDb . 下载地址:https://download.csdn.net/download/a155657721 ...
- mysql的初次使用操作
一.mysql 登录 mysql 参数 mysql -uroot -p123 -P3306 -h127.0.0.1 127.0.0.1本地回环地址 二.mysql退出 mysql >exit; ...