python webdriver测试报告
2015-03-31 15:08
435 查看
即将开始一系列的自动化项目实践,很多公共类和属性都需要提前搞定。今天,解决了测试报告的一些难题,参照了很多博文,最终觉得HTMLTestRunner非常不错,自己也研读了源码,可进行一些自定义的配置。
下面就说一些体会:
一、配置:
HTMLTestRunner看了源码才知道作者是:Wai Yip Tung.到底这是哪位大神就不做深究了,至少我很敬佩。
1、下载HTMLTestRunner.py文件:地址http://tungwaiyip.info/software/HTMLTestRunner.html
2、将该文件保存在python安装路径下的lib文件夹中。在文件中能import HTMLTestRunner成功,即配置成功。
注:如果失败,在项目中新建一个这样的文件也是可以的,只要达到能引入和使用就行。
二、使用
引入完成后,在调用测试文件中加入如下代码即可:
if __name__ == '__main__':
testunit=unittest.TestSuite() #定义一个单元测试容器
testunit.addTest(element("test_find_element")) #将测试用例加入到测试容器中
testunit.addTest(element("test_search"))
filename="./xxx.html" #定义个报告存放路径,支持相对路径。
fp=file(filename,'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title='Report_title',description='Report_description') #使用HTMLTestRunner配置参数,输出报告路径、报告标题、描述
runner.run(testunit) #自动进行测试
生成报告如下:
element:单元测试类名
test_find_element:测试用例方法名
详细信息:测试用例方法中print的数据、出错后信息。
附上单元测试里的一些方法:
常用方法:
assertEqual(a, b) a == b
assertNotEqual(a, b) a != b
assertTrue(x) bool(x) is True
assertFalse(x) bool(x) is False
assertIs(a, b) a is b #python 2.7
assertIsNot(a, b) a is not b #python
2.7
assertIsNone(x) x is None #python
2.7
assertIsNotNone(x) x is not None #python
2.7
assertIn(a, b) a in b #python
2.7
assertNotIn(a, b) a not in b #python
2.7
assertIsInstance(a, b) isinstance(a, b) #python
2.7
assertNotIsInstance(a, b) not isinstance(a, b) #python
2.7
用于执行更具体的检查,如:
Method Checks that New in
assertAlmostEqual(a, b) round(a-b, 7) == 0
assertNotAlmostEqual(a, b) round(a-b, 7) != 0
assertGreater(a, b) a > b #python
2.7
assertGreaterEqual(a, b) a >= b #python
2.7
assertLess(a, b) a < b #python
2.7
assertLessEqual(a, b) a <= b #python
2.7
assertRegexpMatches(s, re) regex.search(s) #python
2.7
assertNotRegexpMatches(s, re) not regex.search(s) #python
2.7
assertItemsEqual(a, b) sorted(a) == sorted(b) and works with unhashable objs
#python 2.7
assertDictContainsSubset(a, b) all the key/value pairs in a exist in
b #python 2.7
assertMultiLineEqual(a, b) strings #python
2.7
assertSequenceEqual(a, b) sequences #python
2.7
assertListEqual(a, b) lists #python
2.7
assertTupleEqual(a, b) tuples #python
2.7
assertSetEqual(a, b) sets or frozensets #python
2.7
assertDictEqual(a, b) dicts #python
2.7
assertMultiLineEqual(a, b) strings #python
2.7
assertSequenceEqual(a, b) sequences #python
2.7
assertListEqual(a, b) lists #python
2.7
assertTupleEqual(a, b) tuples #python
2.7
assertSetEqual(a, b) sets or frozensets #python
2.7
assertDictEqual(a, b) dicts #python
2.7
更多请参见:http://docs.python.org/2/library/unittest.html
正在品读源码,下次在专门写下里面的东西。
下面就说一些体会:
一、配置:
HTMLTestRunner看了源码才知道作者是:Wai Yip Tung.到底这是哪位大神就不做深究了,至少我很敬佩。
1、下载HTMLTestRunner.py文件:地址http://tungwaiyip.info/software/HTMLTestRunner.html
2、将该文件保存在python安装路径下的lib文件夹中。在文件中能import HTMLTestRunner成功,即配置成功。
注:如果失败,在项目中新建一个这样的文件也是可以的,只要达到能引入和使用就行。
二、使用
引入完成后,在调用测试文件中加入如下代码即可:
if __name__ == '__main__':
testunit=unittest.TestSuite() #定义一个单元测试容器
testunit.addTest(element("test_find_element")) #将测试用例加入到测试容器中
testunit.addTest(element("test_search"))
filename="./xxx.html" #定义个报告存放路径,支持相对路径。
fp=file(filename,'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title='Report_title',description='Report_description') #使用HTMLTestRunner配置参数,输出报告路径、报告标题、描述
runner.run(testunit) #自动进行测试
生成报告如下:
element:单元测试类名
test_find_element:测试用例方法名
详细信息:测试用例方法中print的数据、出错后信息。
附上单元测试里的一些方法:
常用方法:
assertEqual(a, b) a == b
assertNotEqual(a, b) a != b
assertTrue(x) bool(x) is True
assertFalse(x) bool(x) is False
assertIs(a, b) a is b #python 2.7
assertIsNot(a, b) a is not b #python
2.7
assertIsNone(x) x is None #python
2.7
assertIsNotNone(x) x is not None #python
2.7
assertIn(a, b) a in b #python
2.7
assertNotIn(a, b) a not in b #python
2.7
assertIsInstance(a, b) isinstance(a, b) #python
2.7
assertNotIsInstance(a, b) not isinstance(a, b) #python
2.7
用于执行更具体的检查,如:
Method Checks that New in
assertAlmostEqual(a, b) round(a-b, 7) == 0
assertNotAlmostEqual(a, b) round(a-b, 7) != 0
assertGreater(a, b) a > b #python
2.7
assertGreaterEqual(a, b) a >= b #python
2.7
assertLess(a, b) a < b #python
2.7
assertLessEqual(a, b) a <= b #python
2.7
assertRegexpMatches(s, re) regex.search(s) #python
2.7
assertNotRegexpMatches(s, re) not regex.search(s) #python
2.7
assertItemsEqual(a, b) sorted(a) == sorted(b) and works with unhashable objs
#python 2.7
assertDictContainsSubset(a, b) all the key/value pairs in a exist in
b #python 2.7
assertMultiLineEqual(a, b) strings #python
2.7
assertSequenceEqual(a, b) sequences #python
2.7
assertListEqual(a, b) lists #python
2.7
assertTupleEqual(a, b) tuples #python
2.7
assertSetEqual(a, b) sets or frozensets #python
2.7
assertDictEqual(a, b) dicts #python
2.7
assertMultiLineEqual(a, b) strings #python
2.7
assertSequenceEqual(a, b) sequences #python
2.7
assertListEqual(a, b) lists #python
2.7
assertTupleEqual(a, b) tuples #python
2.7
assertSetEqual(a, b) sets or frozensets #python
2.7
assertDictEqual(a, b) dicts #python
2.7
更多请参见:http://docs.python.org/2/library/unittest.html
正在品读源码,下次在专门写下里面的东西。
相关文章推荐
- python webdriver测试报告
- python webdriver测试报告
- python selenium-webdriver 生成测试报告 (十四)
- selenium webdriver实现自动截图与Junit导出report测试报告
- Python爬虫工具 Selenium webdriver -自动化测试工具
- selenium webdriver测试报告
- Python selenium+webdriver 自动化测试例子
- selenium webdriver+testng自定义html测试报告
- Selenium Webdriver Python 测试环境搭建
- python webdriver执行所有测试用例脚本
- Webdriver+Testng自定义html测试报告
- 用Python selenium+webdriver的一个简单的登录自动化测试--豆丁网登录测试
- ruby+selenium-webdriver一步一步完成自动化测试(6)—-生成测试报告
- ruby+selenium-webdriver一步一步完成自动化测试----生成测试报告
- selenium webdriver w/python learning
- Selenium的RC方式编写的测试脚本部分迁移到WebDriver方式混用的简单示例
- ruby+selenium-webdriver一步一步完成自动化测试-----多个测试用例
- 使用Ant构建web项目 从编译到测试 生成测试报告 打包 邮件发送 远程下载tomcat 部署运行一条龙服务之ant脚本
- Selenium的RC方式编写的测试脚本部分迁移到WebDriver方式混用的简单示例