selenium之批量執行測試案例產生HTML結果檔案

來源:互聯網
上載者:User

標籤: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結果檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.