HttpRunner--自定義輸出報(bào)告

httprunner

因?yàn)榻荒暌恢痹谧鼋涌跍y(cè)試,所以選了httprunner框架做接口自動(dòng)化

  • httprunner版本:2.0.5,jinja2版本:2.10
  • httprunner輸出的html測(cè)試報(bào)告:默認(rèn)的模板文件的路勁為 httprunner/templates/report_template.html(使用的是jinja2的格式),可在report.py中的render_html_report方法中找到
report.py源碼分析
  • jinja2介紹:
from jinja2 import Template

template = Template('Test {{ hello }} {{ name}}')
template.render(hello='Hello', name='World!')         # 返回: Test Hello World!
template.render({"hello": "Hello", "name": "World!"})  # 效果同上

修改默認(rèn)輸出報(bào)告

前提:httprunner默認(rèn)輸出的報(bào)告中包含所有測(cè)試用例的執(zhí)行狀態(tài),而且無法直接篩選失敗的測(cè)試用例,所以當(dāng)測(cè)試用例很多時(shí),想要找到執(zhí)行失敗的用例會(huì)比較麻煩

目的:只輸出執(zhí)行失敗的用例文件

具體方法:

  1. 復(fù)制原report_template.html,將其中一個(gè)命名為report_fail_only.html
  2. 修改report_fail_only.html模板文件
  • jinja2的判斷語句為:{% if %}和{% endif %}
改動(dòng)如圖

執(zhí)行命令

# 使用默認(rèn)的 report_template.html
hrun testcases/login.yaml

# 使用自定義的模板,可以指定相對(duì)路徑或絕對(duì)路徑
hrun testcases/login.yaml --report-template=templates/report_fail_only.html

# 控制臺(tái)打印日志類型為debug(輸出詳細(xì)的請(qǐng)求),默認(rèn)為INFO
hrun testcases/login.yaml --log-level=debug

# 將login.yaml對(duì)應(yīng)的logs輸出:x.loaded.json, x.parsed.json, x.summary.json
hrun testcases/login.yaml --save-tests
  • httprunner命令運(yùn)行底層:運(yùn)行hrun.exe命令--->運(yùn)行cli.py文件的main_hrun()--->調(diào)用api.py文件中的HttpRunner類的run方法--->執(zhí)行api.py中的run_tests()----》調(diào)用loader.py,report.py中的相關(guān)方法,加載測(cè)試用例,執(zhí)行用例,以及生成報(bào)告。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容