1. 程式人生 > >python+selenium+unittest 生成報告優化

python+selenium+unittest 生成報告優化

1.原版,網上查找了很多,用的都是HTMLTestRunner這個庫,生成的報告是這樣的
這裡寫圖片描述
是不是很不美觀
2.無意中看到了一個,在這裡記錄一下
報告下載地址:https://github.com/TesterlifeRaymond/BeautifulReport
3.下載到本地:
這裡寫圖片描述
4.解壓到python下所示目錄
這裡寫圖片描述
5.程式碼中引用

import os
import unittest 
from testsuit.XXXXX  import XXXXX
from BeautifulReport import BeautifulReport#匯入哦
import time

if
__name__ == '__main__': '''這裡載入suite,我是這樣加的''' #suite1= unittest.TestLoader().loadTestsFromTestCase(QjTest)#請假 suite2= unittest.TestLoader().loadTestsFromTestCase(Trave_request) suite3= unittest.TestLoader().loadTestsFromTestCase(Trave_request02) suite4= unittest.TestLoader().loadTestsFromTestCase(Trave_request03) list =[suite2,suite3,suite4] suite = unittest.TestSuite(list) #按這裡順序執行
# 設定報告檔案儲存路徑 report_dir = os.path.abspath('.').split('src')[0] + '/report/' # 獲取系統當前時間 now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) # 設定報告名稱格式 HtmlFile = now + "Report.html" result = BeautifulReport(suite) result.report(filename=HtmlFile, description='專案測試報告'
, log_path=report_dir)

6.執行,生成的報告:
這裡寫圖片描述
是不是美多了!!