HTMLTestRunner 自动化测试报告


下载,将下载后的文件放在python的Lib目录下

1 # -*- coding:utf-8 -*- 2 3 import HTMLTestRunner 4 import unittest 5 from selenium import webdriver 6 7 class ResultDemo(unittest.TestCase): 8 9 def setUp(self): 10 self.driver = webdriver.Firefox() 11 self.url = \'\' 12 13 def test_login(self): 14 driver = self.driver 15 driver.get(self.url) 16 17 driver.find_element_by_id(\'username\').clear() 18 driver.find_element_by_id(\'username\').send_keys(\'xxxxxx\') 19 20 driver.find_element_by_id(\'userpass\').clear() 21 driver.find_element_by_id(\'userpass\').send_keys(\'xxxxxx\') 22 23 driver.find_element_by_id(\'dologin\').click() 24 25 driver.find_element_by_id(\'xspace-seccode\').clear() 26 input_seccode = raw_input(\'请输入验证码,并按 Enter 键:\') 27 driver.find_element_by_id(\'xspace-seccode\').send_keys(input_seccode) 28 driver.find_element_by_id(\'securitysubmit\').click() 29 30 def tearDown(self): 31 self.driver.quit() 32 #pass 33 34 if __name__ == "__main__": 35 testsuite = unittest.TestSuite() 36 #添加测试用例到测试集中 37 testsuite.addTest(ResultDemo("test_login")) 38 39 #生成测试报告文件 40 file_name = "D:/result.html" 41 fp = file(file_name, \'wb\') 42 43 renner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=\'测试结果\', description=\'测试报告\') 44 renner.run(testsuite)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgdzyw.html