Python + Selenium notes (5): Generate Test Report, pythonselenium
# HTMLTestRunnerFor details about code modification, refer to the instructions on smiling. The following is a link.
Https://www.cnblogs.com/miniren/p/5301081.html
(1)Preface
Unittest outputs test results on the command line. You may need to generate the execution results of all tests as a report or send the test results to relevant personnel. Sending command line logs to relevant personnel is not a wise choice. They need a more user-friendly test report to view both the test results and details.
(2)Use HTMLTestRunner to generate a test report
HTMLTestRunner is an extension of unittest compiled by Wai Yip Tung.
Http://tungwaiyip.info/software/HTMLTestRunner.html downloading code
(3)Smoketests. py
ImportUnittest
ImportHTMLTestRunner
ImportOS
FromSearchtestImportSearchTest
FromHomepagetestImportHomePageTest
Dir = OS. getcwd ()
#Obtain all the test methods in the SearchTest class and HomePageTest class.
Search_test = unittest. TestLoader (). loadTestsFromTestCase (SearchTest)
Home_page_test = unittest. TestLoader (). loadTestsFromTestCase (HomePageTest)
#Create a test suite that includes SearchTest and HomePageTest
Smoke_tests = unittest. TestSuite ([home_page_test, search_test])
#Open a file in binary format for writing
Outfile = open (dir +"\ SmokeTestReport.html","Wb")
#Configure HTMLTestRunner
Runner = HTMLTestRunner. HTMLTestRunner (stream = outfile, title ='Test report', Description ='Smoketests')
#Run the test suite through HTMLTestRunner
Runner. run (smoke_tests)
(4)Run smoketests. py to generate the test report
HTMLTestRunner runs all tests like the default test executor of unittest. At the end of case execution, it generates a test report file, as shown in.
(5)Note 1 to 5 all sample code
Https://pan.baidu.com/s/1qZJHuyS