Use Htmltestrunner to run a test suite to automatically generate an HTML test report:
1 Importunittest, Htmltestrunner, sendmail_html2 ImportTime , Os3 4Case_dir ='d:\\pywork\\pyworkspace\\yzwx_selenium\\batch_case\\test_cases'5t = time.strftime ("%y%m%d_%h%m%s", Time.localtime ())6Html_name ='D:\\test_data\\auto_test_result\\result_'+ T +'. html'7Result_dir ='D:\\test_data\\auto_test_result'8 9 Ten defsuites_run_html (): One " "use Htmltestrunner to run test suites to automatically generate HTML test reports" " A #the Discover function iterates through the specified directory, filters the files conditionally, and returns to the list of test suites -Discover_suites = Unittest.defaultTestLoader.discover (Case_dir, pattern='test_*.py') - Print(discover_suites) thefp = open (Html_name,'WB') -Runner =Htmltestrunner.htmltestrunner ( -stream=FP, -title='Automated test Report for hazardous weather projects in Asia', +description='use case execution:') - Runner.run (discover_suites) + fp.close () A Print("test result file:", Html_name) at - - defdel_empty_html (): - " "to delete an empty HTML file that was previously generated" " -Lastest_file =sendmail_html.find_new_file (Result_dir) -File_size =os.path.getsize (lastest_file) in iffile_size: - Pass to Else: + Os.remove (lastest_file) - Print("The last result file is empty, deleted! ", Lastest_file) the * $Del_empty_html ()#to delete an empty HTML file that was previously generatedPanax NotoginsengSuites_run_html ()#executing a test suite
Selenium batch execution test case generates HTML result file