接口自动化测试接口测试

HttpRunner--自定义输出报告

2019-02-15  本文已影响0人  Cassie测试路

httprunner

因为近一年一直在做接口测试,所以选了httprunner框架做接口自动化

report.py源码分析
from jinja2 import Template

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

修改默认输出报告

前提:httprunner默认输出的报告中包含所有测试用例的执行状态,而且无法直接筛选失败的测试用例,所以当测试用例很多时,想要找到执行失败的用例会比较麻烦

目的:只输出执行失败的用例文件

具体方法:

  1. 复制原report_template.html,将其中一个命名为report_fail_only.html
  2. 修改report_fail_only.html模板文件
改动如图

执行命令

# 使用默认的 report_template.html
hrun testcases/login.yaml

# 使用自定义的模板,可以指定相对路径或绝对路径
hrun testcases/login.yaml --report-template=templates/report_fail_only.html

# 控制台打印日志类型为debug(输出详细的请求),默认为INFO
hrun testcases/login.yaml --log-level=debug

# 将login.yaml对应的logs输出:x.loaded.json, x.parsed.json, x.summary.json
hrun testcases/login.yaml --save-tests
上一篇 下一篇

猜你喜欢

热点阅读