前言

httprunner默认生成的报告不怎么美观,里面还有第二套报告模板extent_report_template.html。

extent_report_template

使用 hrun -h 可以看到运行的时候可以添加的命令行参数

C:\Users\dell>hrun -h
usage: hrun [-h] [-V] [--no-html-report] [--html-report-name HTML_REPORT_NAME]
[--html-report-template HTML_REPORT_TEMPLATE]
[--log-level LOG_LEVEL] [--log-file LOG_FILE]
[--dot-env-path DOT_ENV_PATH] [--failfast]
[--startproject STARTPROJECT]
[--validate [VALIDATE [VALIDATE ...]]]
[--prettify [PRETTIFY [PRETTIFY ...]]]
[testset_paths [testset_paths ...]] One-stop solution for HTTP(S) testing. positional arguments:
testset_paths testset file path optional arguments:
-h, --help show this help message and exit
-V, --version show version
--no-html-report do not generate html report.
--html-report-name HTML_REPORT_NAME
specify html report name, only effective when
generating html report.
--html-report-template HTML_REPORT_TEMPLATE
specify html report template path.
--log-level LOG_LEVEL
Specify logging level, default is INFO.
--log-file LOG_FILE Write logs to specified file path.
--dot-env-path DOT_ENV_PATH
Specify .env file path, which is useful for keeping
production credentials.
--failfast Stop the test run on the first error or failure.
--startproject STARTPROJECT
Specify new project name.
--validate [VALIDATE [VALIDATE ...]]
Validate JSON testset format.
--prettify [PRETTIFY [PRETTIFY ...]]
Prettify JSON testset format.

使用 --html-report-template参数可以替换自己的模板,后面指定模板的路径:E:\python36\Lib\site-packages\httprunner\templates\extent_report_template.html

hrun test_demo.yml --html-report-template /path/templates/extent_report_template.html

D:\soft\untitled>hrun test_demo.yml --html-report-template E:\python36\Lib\site-packages\httprunner\templates\extent_report_template.html
test_demo case1
INFO GET http://127.0.0.1:8000/api/test/demo
INFO status_code: 200, response_time(ms): 39.2 ms, response_length: 255 bytes
INFO start to extract from response object.
INFO start to validate.
. ----------------------------------------------------------------------
Ran 1 test in 0.049s OK
INFO render with html report template: E:\python36\Lib\site-packages\httprunner\templates\extent_report_template.html
INFO Start to render Html report ...
INFO Generated Html report: D:\soft\untitled\reports\1569369482.html D:\soft\untitled>

查看extentreport报告

查看extentreport测试报告,默认黑色主题

也可以切换成白色主题

默认使用extentreport报告

如果你不想每次输入这么长的参数,我们可以修改源码。默认使用extent_report_template.html

找到\site-packages\httprunner\report.py文件,相关代码

def render_html_report(summary, html_report_name=None, html_report_template=None):
""" render html report with specified report name and template
if html_report_name is not specified, use current datetime
if html_report_template is not specified, use default report template
"""
if not html_report_template:
html_report_template = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"templates",
"default_report_template.html"
)
logger.log_debug("No html report template specified, use default.")
else:
logger.log_info("render with html report template: {}".format(html_report_template))

修改后代码

def render_html_report(summary, html_report_name=None, html_report_template=None):
""" render html report with specified report name and template
if html_report_name is not specified, use current datetime
if html_report_template is not specified, use default report template
"""
if not html_report_template:
html_report_template = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"templates",
"extent_report_template.html"
)
logger.log_debug("No html report template specified, use extent_report_template.")
elif html_report_template == 'default':
html_report_template = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"templates",
"default_report_template.html"
)
logger.log_debug("render with html report template: default_report_template.")
else:
logger.log_info("render with html report template: {}".format(html_report_template))

这样默认就会生成extentreport

hrun test_demo.yml

带上default参数就会生成原始的报告

hrun test_demo.yml --html-report-template default

httprunner学习10-测试报告ExtentReport的更多相关文章

  1. httprunner学习15-运行用例命令行参数详解

    前言 HttpRunner 在命令行中启动测试时,通过指定参数,可实现丰富的测试特性控制. 命令行参数CLI 使用 -h 查看相关命令行参数 hrun -h 参数名称 参数值 参数说明 -h, --h ...

  2. JavaScript学习10 JS数据类型、强制类型转换和对象属性

    JavaScript学习10 JS数据类型.强制类型转换和对象属性 JavaScript数据类型 JavaScript中有五种原始数据类型:Undefined.Null.Boolean.Number以 ...

  3. ThinkPhp学习10

    原文:ThinkPhp学习10 查询操作 Action模块 User下的search public function search(){ //判断username是否已经传入,且不为空 if(isse ...

  4. HttpRunner学习8--使用debugtalk.py辅助函数

    前言 在HttpRunner中,我们的测试用例都是写在 YAML/JSON 文件中,有时候我们想借助代码来实现某些较复杂的功能,但在 YAML/JSON 中是无法直接写代码来处理的,这个时候,我们可以 ...

  5. python学习10—迭代器、三元表达式与生成器

    python学习10—迭代器.三元表达式与生成器 1. 迭代器协议 定义:对象必须提供一个next方法,执行该方法或者返回迭代中的下一项,或者返回一个StopIteration异常,以终止迭代(只能往 ...

  6. HttpRunner学习9--切换测试报告模板

    前言 在HttpRunner中,给我们提供了 2 套测试报告模板,分别是 default_report_template.html 和 extent_report_template.html . 默认 ...

  7. HttpRunner学习6--使用parameters参数化

    前言 在使用HttpRunner测试过程中,我们可能会遇到这种场景: 账号登录功能,需要输入用户名和密码,设计测试用例后有 N 种组合情况 如果测试组合比较少,比如只有2个,那我们直接在YAML脚本中 ...

  8. HttpRunner学习7--引用CSV文件数据

    前言 在之前的文章中,我们已经学习了 parameters 参数化,是在测试脚本中直接指定参数列表.这种方法简单易用,但如果我们的参数列表数据比较多,这种方法可能就不太适合了. 当数据量比较大的时候, ...

  9. HttpRunner学习2--用例格式和简单使用

    前言 HttpRunner中,测试用例支持两种文件格式:YAML 和 JSON.两种格式的用例是完全等价的,对于相同的信息内容,使用 YAML /JSON 得到的测试结果和报告也是一致的. 本人环境: ...

随机推荐

  1. Java集合详解2:一文读懂Queue和LinkedList

    <Java集合详解系列>是我在完成夯实Java基础篇的系列博客后准备开始写的新系列. 这些文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查 ...

  2. Burp Suite 入门教程(BURP SUITE TUTORIAL )

    参考链接1:https://www.pentestgeek.com/what-is-burpsuite 参考链接2:https://www.pentestgeek.com/web-applicatio ...

  3. STL源码剖析 阅读笔记

    结构图:

  4. 爬虫(一)基础知识(python)

    1.1 定义 网络爬虫,也叫网络蜘蛛(Web Spider),如果把互联网比喻成一个蜘蛛网,Spider就是一只在网上爬来爬去的蜘蛛.网络爬虫就是根据网页的地址来寻找网页的,也就是URL.举一个简单的 ...

  5. SGE部署安装

    1.关闭防火墙 systemctl stop firewalld.service systemctl disable firewalld.service 2.安装SGE依赖包 # yum instal ...

  6. Mysql常见注意事项小记

    1. 排序问题 正常如果按照某字段升序排列,空值会排到有值的前面;如果逆序排序空值排在最后. 有时候我们需要该字段为空的行数据要排到最后面去,这时只需要: order by second_parent ...

  7. php 求商数和余数 的函数

    //返回两数相除之商和余数function get_div_and_mod($left_operand, $right_operand){ $div = intval($left_operand / ...

  8. 【题解】Luogu P5291 [十二省联考2019]希望

    ytq鸽鸽出的题真是毒瘤 原题传送门 题目大意: 有一棵有\(n\)个点的树,求有多少方案选\(k\)个联通块使得存在一个中心点\(p\),所有\(k\)个联通块中所有点到\(p\)的距离都\(\le ...

  9. go 学习笔记---chan

    如果说 goroutine 是 Go语言程序的并发体的话,那么 channels 就是它们之间的通信机制.一个 channels 是一个通信机制,它可以让一个 goroutine 通过它给另一个 go ...

  10. Java异常的10个关键知识点

    前言 总结了Java异常十个关键知识点,面试或者工作中都有用哦,加油. 一. 异常是什么 异常是指阻止当前方法或作用域继续执行的问题.比如你读取的文件不存在,数组越界,进行除法时,除数为0等都会导致异 ...