前置條件:
httprunner版本:HttpRunner 3.0.1
python版本:3.8
運行環境:Mac
一、很多文章里面都說http runner包里面自帶了自定義的報告模板,但是這個版本沒有,於是網上下載了自定義的extentreports報告模板
運行加參數: --report-template reports/template/extent-theme-template_new.html
報錯: jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'meta_data'
解決方案:出現問題的原因是不同版本的httprunner,運行case的結果匯總的數據結構有些不同,需根據實際版本情況進行調整
1.先根據httprunner對外提供的運行用例的接口runner.run(),查看testcase運行的結果匯總的數據結構
from httprunner.api import HttpRunner
def print_summary_result(path_or_tests):
runner = HttpRunner(
failfast=True,
save_tests=True,
log_level="INFO",
log_file="test.log"
)
summary = runner.run(path_or_tests)
return summary
2.根據運行的結果匯總的數據結構,修過extentreports報告模板的取值數據的字段信息,我遇到的情況是打印出來的結果的結構跟模板中的字段取值結構不同
二、報告中無法加載css和js
解決方案:下載對應的css和js文件到本地,然后在模板中引用
1.在https://github.com/anshooarora/extentreports-java/tree/master/dist下,下載對應的css和js文件到本地,放到項目中的指定目錄下,如
2.修過自定義的模板文件,修過如下