selenium

1. 直接上代码,如下:

 1 from HTMLTestRunner import HTMLTestRunner    # 导入HTMLTestRunner模块
 2 import unittest
 3 import time
 4 
 5 
 6 class Test(unittest.TestCase):
 7     '我的一个测试类'          # 使用docstring,为测试报告的用例加上标题
 8 
 9     @classmethod
10     def setUp(self):
11         pass
12 
13     def test_case_1(self):
14         '''测试2是否等于2'''
15         self.assertEqual(2, 2, '不相等2!=2')
16 
17     def test_case_2(self):
18         '''测试2是否等于3'''
19         self.assertEqual(2, 3, '不相等2!=3')
20 
21     @classmethod
22     def tearDown(self):
23         pass
24 
25 
26 if __name__ == '__main__':
27     # 构建测试集
28     suite = unittest.TestSuite()
29     suite.addTest(Test('test_case_1'))
30     suite.addTest(Test('test_case_2'))
31 
32     now_time = time.strftime('%Y-%m-%d %H_%M_%S')    # 获取当前时间
33     file_name = './testresult' + now_time + '.html'  # 组装路径及文件名
34     fp = open(file_name, 'wb')                       # 以二进制写方式,打开文件;如果没有,则新建一个
35     runner = HTMLTestRunner(stream=fp,                        # 指定报告文件
36                             title='测试2是否等于2的测试报告',     # 指定报告标题
37                             description='运行环境:win10,chrome浏览器')        # 指定报告描述
38     runner.run(suite)
39     fp.close()           # 关闭测试报告文件

2. 报告列表如下:

 3. 报告内容如下:

 4. 展开fail项的内容,查看具体错误信息,如下:

原文地址:https://www.cnblogs.com/xiaochongc/p/12606043.html