httprunner学习10-测试报告ExtentReport
前言
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的更多相关文章
- httprunner学习15-运行用例命令行参数详解
前言 HttpRunner 在命令行中启动测试时,通过指定参数,可实现丰富的测试特性控制. 命令行参数CLI 使用 -h 查看相关命令行参数 hrun -h 参数名称 参数值 参数说明 -h, --h ...
- JavaScript学习10 JS数据类型、强制类型转换和对象属性
JavaScript学习10 JS数据类型.强制类型转换和对象属性 JavaScript数据类型 JavaScript中有五种原始数据类型:Undefined.Null.Boolean.Number以 ...
- ThinkPhp学习10
原文:ThinkPhp学习10 查询操作 Action模块 User下的search public function search(){ //判断username是否已经传入,且不为空 if(isse ...
- HttpRunner学习8--使用debugtalk.py辅助函数
前言 在HttpRunner中,我们的测试用例都是写在 YAML/JSON 文件中,有时候我们想借助代码来实现某些较复杂的功能,但在 YAML/JSON 中是无法直接写代码来处理的,这个时候,我们可以 ...
- python学习10—迭代器、三元表达式与生成器
python学习10—迭代器.三元表达式与生成器 1. 迭代器协议 定义:对象必须提供一个next方法,执行该方法或者返回迭代中的下一项,或者返回一个StopIteration异常,以终止迭代(只能往 ...
- HttpRunner学习9--切换测试报告模板
前言 在HttpRunner中,给我们提供了 2 套测试报告模板,分别是 default_report_template.html 和 extent_report_template.html . 默认 ...
- HttpRunner学习6--使用parameters参数化
前言 在使用HttpRunner测试过程中,我们可能会遇到这种场景: 账号登录功能,需要输入用户名和密码,设计测试用例后有 N 种组合情况 如果测试组合比较少,比如只有2个,那我们直接在YAML脚本中 ...
- HttpRunner学习7--引用CSV文件数据
前言 在之前的文章中,我们已经学习了 parameters 参数化,是在测试脚本中直接指定参数列表.这种方法简单易用,但如果我们的参数列表数据比较多,这种方法可能就不太适合了. 当数据量比较大的时候, ...
- HttpRunner学习2--用例格式和简单使用
前言 HttpRunner中,测试用例支持两种文件格式:YAML 和 JSON.两种格式的用例是完全等价的,对于相同的信息内容,使用 YAML /JSON 得到的测试结果和报告也是一致的. 本人环境: ...
随机推荐
- .NETCore_项目启动设置域名以及端口
//第一种方式就是启动是一个命令窗口 public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.C ...
- java并发编程(九)ThreadLocal & InheritableThreadLocal
参考文档: https://blog.csdn.net/u012834750/article/details/71646700 threadlocal内存泄漏:http://www.importnew ...
- mongo 复制一个表的数据到另一个表中
club表: { "_id" : ObjectId("592e94fee820cc1813f0b9a2"), "id":1, "n ...
- 停止IIS服务
1 第一步 停止 World Wide Web Publishing Service 这个是W3C服务 2 第二部 停止 IIS Admin Service 这个IIS元数据管理服务
- nginx mysqlnd驱动引擎提升mysql性能
nginx mysqlnd驱动引擎提升mysql性能 前期要安装 mysql mysqli pdo_mysql libiconv 1 先去PHP官网下个 php-5.6.29.tar.gz wget ...
- javascript 函数的暂停和恢复
javascript 异步编程从来都是一个难题,最开始我们用 callback,但随之触发了回调地狱,于是"发明" Promise 解决 callback 嵌套过深的问题.然而由于 ...
- Spring Boot 2整合Redis做缓存
既然是要用Redis做缓存,自然少不了安装了.但是本文主要讲Spring Boot与Redis整合.安装教程请另行百度! 1.首先是我们的Redis配置类 package com.tyc; impor ...
- C 编程环境搭建 Window 篇
前言 - 简介 我们在写代码的过程中, 不可避免的重度依赖所处的开发环境. 本文重点带大家在 Window 搭建 C 简单控制台项目. 当作存档, 用于记录项目搭建各种重复操作. 在详细过程之前, ...
- 一个萝卜一个坑#M坑—Polynomial、Polyder
Polynomial 作用:对输入值执行多项式系数计算,输入输出都可为实数标量或向量. 库:Simulink / Math Operations Polyval 作用:多项式计算,即求多项式在某一点的 ...
- C# 单向链表 逆序(递归)
static void Main(string[] args) { while (true) { LinkedList L = new LinkedList(); L.Add(new Node(&qu ...