前言

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. Echart、Excel、highcharts、jfreechart对比

      Echart Excel highcharts jfreechart 柱状图 √ √ √ √ 条形图 √ √ √ √ 折线图 √ √ √ √ 面积图 √ √ √ √ 散点图 √ √ √ √ 气泡图 ...

  2. Linux 就该这么学 CH05 用户的身份和文件权限

    1 用户权限与能力 超级用户root拥有最高的系统所有权,能够管理系统的各项功能,如添加.删除用户:启动或关闭服务进程:开启或禁用硬件设备等. 用户身份分类: 系统管理员root :UID = 0; ...

  3. cad.net 2008使用WPF(摘录山人)

    由于WPF的优点多多,而且在大量的winform的操作下感觉到数据操作的麻烦....推荐大家看杨中科WPF数据绑定教程 https://www.bilibili.com/video/av3388348 ...

  4. NanoPi NEO Plus2开发环境搭建

    1.前言 NanoPi NEO Plus2是友善电子推出的一款非常小巧精致的开源硬件,该开源硬件的CPU是基于Allwinner公司的64位四核ARM Cortex-A53处理器H5,并且内置了六核M ...

  5. Elasticsearch 7.1.1 安装 pinyin 分词器插件

    1.安装maven 安装插件前,需要用 maven 进行编译生成插件包,第一步先安装 maven yum install -y maven mvn -version Apache Maven (Red ...

  6. Zookeeper的介绍与基本部署

    目录 简介 架构 安装 StandAlone模式 1. 安装 2. 修改配置 3. 启动 4. 验证 5. 基本用法 Distributed模式 1. 配置hosts 2. 配置zoo.cfg 3. ...

  7. [转帖]String、StringBuilder与StringBuffer

    String.StringBuilder与StringBuffer https://www.jianshu.com/p/37f3799bdb56 1.String String本质 String是不可 ...

  8. sublime text 开发记录贴

    1.展示信息有两种: self.view.show_popup('hello'), 这个好看点. sublime.status_message('ssss')    sublime.error_mes ...

  9. mysql获取某个字段平均值方法AVG函数的使用

    直接上脚本 ,)) AS 平均分 FROM students WHERE sex= '男' 其中,特别说明一下CAST关键字 CAST(字段名 as 要转换的类型) #其中,可以转换的类型为: CHA ...

  10. Angular的Observable可观察对象(转)

    原文:https://blog.csdn.net/qq_34414916/article/details/85194098 Observable 在开始讲服务之前,我们先来看一下一个新东西——Obse ...