前言

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. python对图片批量命名

    深度学习中经常会有批量对图片进行重命名,从网上看到的资料整理一下,方便以后查看. import os class BatchRename(): ''' 批量重命名文件夹中的图片文件 ''' def _ ...

  2. leetcode 763. 划分字母区间

    题目描述: 字符串 S 由小写字母组成.我们要把这个字符串划分为尽可能多的片段,同一个字母只会出现在其中的一个片段.返回一个表示每个字符串片段的长度的列表. 示例 1: 输入: S = "a ...

  3. 【07月01日】A股滚动市净率PB历史新低排名

    2010年01月01日 到 2019年07月01日 之间,滚动市净率历史新低排名. 上市三年以上的公司,2019年07月01日市净率在30以下的公司. 来源:A股滚动市净率(PB)历史新低排名. 1 ...

  4. 【神经网络与深度学习】neural-style、chainer-fast-neuralstyle图像风格转换使用

    neural-style 官方地址:这个是使用torch7实现的;torch7安装比较麻烦.我这里使用的是大神使用TensorFlow实现的https://github.com/anishathaly ...

  5. SQL工具 Red Gate

    Red Gate提供了很多对于sql server的工具. 这边介绍两个:Sql Prompt和Sql doc Sql Prompt:智能提示sql语句等等 Sql doc:生成数据库文档页面 Red ...

  6. cad.net 定义lisp

    首先是传参型lisp的定义: (addLine (getpoint)) //定义lisp传入参数的例子 //复制到命令栏运行: (addLine (getpoint)) [LispFunction(& ...

  7. IO流一些问题的总结

    字节流的继承体系 字符流的继承体系 字符编码是什么?常见的字符编码表有哪些? 字符编码(英语:Character encoding)也称字集码,是把字符集中的字符编码为指定集合中某一对象,以便文本在计 ...

  8. PatchMatch笔记

    关键词: slanted surfaces: 倾斜的平面 fronto-parallel windows: ??? remedy: 补救 disparity: 视差图 对每一个像素都估计一个3D平面. ...

  9. windows,office激活工具推荐

    微软的操作系统windows,办公软件office,都需要付费.今天,蒟蒻菌带来一部软件,可以激活上述软件,那就是: heu_kms_activator_v19.5.1 二话不说,立即使用: 可以根据 ...

  10. Mysql系列(六)—— MySQL索引介绍

    前言 索引种类 索引维护 如何使用索引 一.索引索引种类 MySQL中索引主要包含以下几种: 普通索引 唯一索引 主键索引 联合索引 全文索引 二.索引维护 在简述了索引的类型后,再来了解下如何维护索 ...