標籤:ftime nbsp path unit script batch load 自動化測試 att
使用HTMLTestRunner運行測試套件,自動產生html測試報告:
1 import unittest, HTMLTestRunner, sendmail_html 2 import time, os 3 4 case_dir = ‘D:\\pywork\\pyworkspace\\yzwx_selenium\\batch_case\\test_cases‘ 5 t = time.strftime("%Y%m%d_%H%M%S", time.localtime()) 6 html_name = ‘D:\\test_data\\auto_test_result\\result_‘ + t + ‘.html‘ 7 result_dir = ‘D:\\test_data\\auto_test_result‘ 8 9 10 def suites_run_html():11 ‘‘‘使用HTMLTestRunner運行測試套件,自動產生html測試報告‘‘‘12 # discover函數遍曆指定目錄,按條件過濾檔案,返回測試套件列表13 discover_suites = unittest.defaultTestLoader.discover(case_dir, pattern=‘test_*.py‘)14 print(discover_suites)15 fp = open(html_name, ‘wb‘)16 runner = HTMLTestRunner.HTMLTestRunner(17 stream=fp,18 title=‘亞洲危險天氣項目自動化測試報告‘,19 description=‘用例執行情況:‘)20 runner.run(discover_suites)21 fp.close()22 print("測試結果檔案:", html_name)23 24 25 def del_empty_html():26 ‘‘‘刪除之前一次產生的空html檔案‘‘‘27 lastest_file = sendmail_html.find_new_file(result_dir)28 file_size = os.path.getsize(lastest_file)29 if file_size:30 pass31 else:32 os.remove(lastest_file)33 print("上次結果檔案為空白,已刪除!", lastest_file)34 35 36 del_empty_html() # 刪除之前一次產生的空html檔案37 suites_run_html() # 執行測試套件
selenium之批量執行測試案例產生HTML結果檔案