HttpRunner学习9--切换测试报告模板
前言
在HttpRunner中,给我们提供了 2 套测试报告模板,分别是 default_report_template.html 和 extent_report_template.html 。
默认报告使用的是 default_report_template ,如果觉得不太美观,这时我们可以使用 extent_report_template ,其生成的报告相对更加漂亮,看起来也更加高大上。
本人环境:HttpRunner V1.5.8
使用ExtentReport模板生成报告
在安装HttpRunner的时候,如果是使用 pip 来安装,那么报告模板的路径在 python 安装路径下的 \Lib\site-packages\httprunner\templates 目录下,如我本地环境的报告模板路径:

第一个是默认情况使用的报告模板,其生成的报告如下:

接下来,我们将使用第二个模板 extent_report_template.html 来生成报告。
在HttpRunner中,如果要指定测试报告的模板,需要通过 --html-report-template 指定报告模板的路径,然后测试运行完成后,就会采用指定模板生成测试报告。
如我在这里使用 extent_report_template 来生成报告:
hrun test_login.yml --html-report-template D:\Python\installation\Lib\site-packages\httprunner\templates\extent_report_template.html
运行完成后,会在当前路径的 reports 目录下生成一份 HTML 格式的测试报告,打开报告可看到:

现在,我们对比一下,是不是能感觉到 extent_report_template 更加美观,逼格更高呢?
指定ExtentReport为默认模板
在上面步骤中,我们发现,使用 extent_report_template 来生成报告,运行命令会比较长,如果我们想将 extent_report_template 作为默认的测试报告模板,那么我们就需对 HttpRunner 的源码进行简单修改了。
HttpRunner中,生成报告相关的源码在 \Lib\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))
logger.log_info("Start to render Html report ...")
logger.log_debug("render data: {}".format(summary))
从源码中看到,如果不指定测试报告模板,那么参数 html_report_template=None ,使用的是 default_report_template.html 这个模板,因此,我们只要将这里修改一下,应该就能够达到我们的目标。
if not html_report_template:
html_report_template = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"templates",
"extent_report_template.html"
)
OK,修改之后,再次执行命令,可以发现,生成测试报告使用的默认模板已修改。
HttpRunner学习9--切换测试报告模板的更多相关文章
- httprunner学习15-运行用例命令行参数详解
前言 HttpRunner 在命令行中启动测试时,通过指定参数,可实现丰富的测试特性控制. 命令行参数CLI 使用 -h 查看相关命令行参数 hrun -h 参数名称 参数值 参数说明 -h, --h ...
- python - HTMLTestRunner 测试报告模板设置
python - HTMLTestRunner 测试报告模板设置 优化模板下载地址: http://download.csdn.net/download/chinayyj2010/10039097 ...
- js用户管理中心tab切换界面模板
效果体验:http://hovertree.com/texiao/js/27/ 效果图如下: 代码如下: <!DOCTYPE html> <html> <head> ...
- python接口自动化(五)--接口测试用例和接口测试报告模板(详解)
简介 当今社会在测试领域,接口测试已经越来越多的被提及,被重视,而且现在好多招聘信息要对接口测试提出要求.区别于传统意义上的系统级别测试,很多测试人员在接触到接口测试的时候,也许对测试执行还可以比较顺 ...
- Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客
==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...
- 迷你MVVM框架 avalonjs 学习教程13、模板引用
稍为复杂一点的网站都是多个前端工程师合作而成,因此分工是必需的.简单一点的分工就是一个人负责一个频道,某个页面是由一个人全部做的:但如果涉及到一个页面非常复杂,需要多个人同时动工呢?于是到模板的出场时 ...
- Flask 学习(三)模板
Flask 学习(三)模板 Flask 为你配置 Jinja2 模板引擎.使用 render_template() 方法可以渲染模板,只需提供模板名称和需要作为参数传递给模板的变量就可简单执行. 至于 ...
- 微信小程序开发:学习笔记[2]——WXML模板
微信小程序开发:学习笔记[2]——WXML模板 快速开始 介绍 WXML 全称是 WeiXin Markup Language,是小程序框架设计的一套标签语言,结合小程序的基础组件.事件系统,可以构建 ...
- HttpRunner学习8--使用debugtalk.py辅助函数
前言 在HttpRunner中,我们的测试用例都是写在 YAML/JSON 文件中,有时候我们想借助代码来实现某些较复杂的功能,但在 YAML/JSON 中是无法直接写代码来处理的,这个时候,我们可以 ...
随机推荐
- C#Windows Forms (Demo.SYS)--xdd
private void Show_background_picture()//随机更换背景 { ";//默认值 Random ran = new Random(); , );//返回一个1 ...
- 3 JAVA的基本变量类型
1. 数字 整数型 类型 字节数 范围 int 4 -2^31~ 2^31-1 short 2 -2^15~ 2^15 -1 long 8 -2^63 ~ 2^63 -1 byte 1 -2^ ...
- JVM系列一(Java内存区域和对象创建).
一.JVM 内存区域 堆 - Heap 线程共享,JVM中最大的一块内存,此内存的唯一目的就是存放对象实例,Java 堆是垃圾收集器管理的主要区域,因此很多时候也被称为"GC堆"( ...
- 使用Cap解决.Netcore分布式事务
一.什么是Cap CAP 是一个基于 .NET Standard 的 C# 库,它是一种处理分布式事务的解决方案,同样具有 EventBus 的功能,它具有轻量级.易使用.高性能等特点. 在我们 ...
- rsync通过服务同步、Linux系统日志、screen工具 使用介绍
第8周5月15日任务 课程内容: 10.32/10.33 rsync通过服务同步10.34 linux系统日志10.35 screen工具 扩展1. Linux日志文件总管logrotate http ...
- shell脚本中的逻辑判断、文件目录属性判断、if特殊用法、case判断
7月12日任务 20.5 shell脚本中的逻辑判断20.6 文件目录属性判断20.7 if特殊用法20.8/20.9 case判断 20.5 shell脚本中的逻辑判断 逻辑判断在shell中随处可 ...
- 【github repo自荐】码农周刊一周精选分类
以下内容节选自我的github码农周刊整理repo,欢迎大家star. 写在最前面的话 作为最初的一批码农周刊的订阅者,不能说经历了其成长,但是确实见证了他的壮大.码农周刊确实从开始第一期的基本上都是 ...
- 鲲鹏性能优化十板斧(二)——CPU与内存子系统性能调优
1.1 CPU与内存子系统性能调优简介 调优思路 性能优化的思路如下: l 如果CPU的利用率不高,说明资源没有充分利用,可以通过工具(如strace)查看应用程序阻塞在哪里,一般为磁盘,网络或应 ...
- 线性规划VB求解
线性规划VB求解 Rem 定义动态数组 Dim a() As Single, c() As Single, b() As Single, cb() As Single Dim aa() As Sing ...
- HDU1517 Multiply Game
Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 t ...