解读并加工BeautifulReport 报告模板
使用unittest框架的脚本执行完成后,会生成一个html格式的报告
这个报告是提前制作了一个html的模板,然后将对应的内容写入到模板中,并生成一个最终的报告,这个报告模板在通过 pip install BeautifulReport后,就会在下面路径中存在:
C:\Program Files\Python37\Lib\site-packages\BeautifulReport\template,这个html模板可以将里面的一些表格属性名称修改为适合自己的名称,例如:
<body class="gray-bg">
<div class="row border-bottom white-bg dashboard-header">
<div class="col-sm-12 text-center">
<span style="${title}">自动化测试报告</span>
</div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-sm-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5 style="${sub-title}">报告汇总</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="row">
<div class="col-sm-6 b-r" style="height:350px">
<form class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label text-info">测试目的:</label>
<div class="col-sm-5">
<span class="form-control" id="testName"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-info">用例总数:</label>
<div class="col-sm-5">
<span class="form-control" id="testAll"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-navy">用例通过:</label>
<div class="col-sm-5">
<span class="form-control" id="testPass"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-danger">用例失败:</label>
<div class="col-sm-5">
<span class="form-control text-danger" id="testFail"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-warning">用例跳过:</label>
<div class="col-sm-5">
<span class="form-control text-warning" id="testSkip"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-info">开始时间:</label>
<div class="col-sm-5">
<span class="form-control" id="beginTime"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-info">运行时间:</label>
<div class="col-sm-5">
<span class="form-control" id="totalTime"></span>
</div>
</div>
</form>
</div>
<div class="col-sm-6">
<div style="height:350px" id="echarts-map-chart"></div>
</div>
</div>
</div>
</div>
</div>
</div>
那么通过这个报告生成,都可以做哪些呢,比较指定存储路径,报告主题等,下面直接看BeautifulReport代码,发现要对这个类实例化时,必须要先传入一个suite(也就是测试用例集),然后调用这个类的report方法进行报告生成时,可以传入哪些参数:description, filename: str = None, report_dir='.', log_path=None, theme='theme_default',除去 log_path废弃后,可以有4个参数进行传入,每个参数的具体用法在代码中都有详细说明,这里不再重复。
class BeautifulReport(ReportTestResult, PATH):
img_path = 'img/' if platform.system() != 'Windows' else 'img\\' def __init__(self, suites):
super(BeautifulReport, self).__init__(suites)
self.suites = suites
self.report_dir = None
self.title = '自动化测试报告'
self.filename = 'report.html' def report(self, description, filename: str = None, report_dir='.', log_path=None, theme='theme_default'):
"""
生成测试报告,并放在当前运行路径下
:param report_dir: 生成report的文件存储路径
:param filename: 生成文件的filename
:param description: 生成文件的注释
:param theme: 报告主题名 theme_default theme_cyan theme_candy theme_memories
:return:
"""
if log_path:
import warnings
message = ('"log_path" is deprecated, please replace with "report_dir"\n'
"e.g. result.report(filename='测试报告_demo', description='测试报告', report_dir='report')")
warnings.warn(message) if filename:
self.filename = filename if filename.endswith('.html') else filename + '.html' if description:
self.title = description self.report_dir = os.path.abspath(report_dir)
os.makedirs(self.report_dir, exist_ok=True)
self.suites.run(result=self)
self.stopTestRun(self.title)
self.output_report(theme)
text = '\n测试已全部完成, 可打开 {} 查看报告'.format(os.path.join(self.report_dir, self.filename))
print(text)
下面列举调用这个模块的实现方法:
# -*- coding:utf-8 -*-
'''
# @Time : 2019/12/3 16:50
# @Author : nihaoya
# @FileName: WeiBo_test.py
# @Software: PyCharm
'''
import os
import time
import unittest
from BeautifulReport import BeautifulReport as bf class WeiBo(unittest.TestCase):
此处省略 if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(WeiBo)
run = bf(suite)
run.report(filename=u"微博测试报告_" + time.strftime("%Y~%m~%d %H~%M~%S"), description=u"以游客形式浏览微博", report_dir="report", theme="theme_memories")
解读并加工BeautifulReport 报告模板的更多相关文章
- 单元测试unittest及报告生成(两种报告模板)
Python中有一个自带的单元测试框架是unittest模块,用它来做单元测试,它里面封装好了一些校验返回的结果方法和一些用例执行前的初始化操作. 在说unittest之前,先说几个概念: TestC ...
- weblogic和was的巡检报告模板
weblogic巡检报告模板 https://max.book118.com/html/2017/0710/121553357.shtm 用jrockit How to tell Our WebLo ...
- Beta 冲刺报告模板
Beta 冲刺报告模板 十分钟左右站立会议,控制好时间,不要在此会议上讨论细节问题. 每组一份博客,组内共享,每人都需提交. 模板 队名:xxx 组员1(组长) 过去两天完成了哪些任务 文字/口头描述 ...
- Alpha 冲刺报告模板
Alpha 冲刺报告模板 Deadline: 十分钟左右站立会议,控制好时间,不要在此会议上讨论细节问题. 每组一份博客,组内共享,每人都需提交. 模板 队名:xxx 组员1(组长) 今天完成了哪些任 ...
- Checkpoint checkup中文报告模板使用
步骤: Step1:下载中文版语言包和字体 https://supportcenter.checkpoint.com/supportcenter/portal?action=portlets.DCFi ...
- BeautifulReport报告
Project description BeautifulReport 一个基于unittest.TestResult模块实现的测试用例模板, 可把测试中的结果通过BeautifulReport整合成 ...
- Jmeter(二十九)Jmeter-Question之“Ant集成报告模板优化”
也是在和朋友探讨的时候,发现一个问题,Jmeter在与Ant集成的时候,通常选用的模板是jmeter自带的两个样式表 该自带的样式,节省了大家搭建框架的时间,不需要自己重新写样式,当然也相对简洁: 做 ...
- Python HTMLTestRunner报告及BeautifulReport报告
import unittest import HTMLTestRunner class Testfunc(unittest.TestCase): def testa(self): "&quo ...
- 测试计划&性能测试分析报告模板(仅供参考)
一.测试计划 1. 引言 1.1 编写目的 2. 参考文档 3. 测试目的 4. 测试范围 4.1 测试对象 4.2 需要测试的特性 4.3 无需测试的特性 5. 测试启动与结束准则 5.1 ...
随机推荐
- HDU1517 Multiply Game
Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 t ...
- CoderForces-913-C
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of gues ...
- JS内置对象-Array之splice-删插替
splice-删除 var arr = [1, 2, 3, 4, 5, 6]; //删除 var delArr = arr.splice(1, 2) console.log(arr); // => ...
- LRU算法与增强
概要本文的想法来自于本人学习MySQL时的一个知识点:MySQL Innodb引擎中对缓冲区的处理.虽然没有仔细研究其源码实现,但其设计仍然启发了我. 本文针对LRU存在的问题,思考一种增强算法来避免 ...
- Python3、setuptools、Pip3安装详解
Python3.setuptools.Pip3安装详解 2017年08月19日 18:58:47 安静的技术控 阅读数:26002 版权声明:本文为博主原创文章,未经博主允许不得转载. http ...
- Java工作流系统jflow向工作处理器传值的方法大全
关键词:工作流快速开发平台 工作流流设计 业务流程管理 asp.net 开源工作流 bpm工作流系统 java工作流主流框架 自定义工作流引擎 表单设计器 流程设计器 在启动开始节点时, ...
- Python—脚本程序生成exe可执行程序(pyinstaller)
一.pyinstaller的简介 Python是一个脚本语言,被解释器解释执行.它的发布方式: .py文件:对于开源项目或者源码没那么重要的,直接提供源码,需要使用者自行安装Python并且安装依赖的 ...
- Android 插件化开发(三):资源插件化
在前面的文章中我们成功的加载了外部的Dex(Apk)并执行了插件的Bean代码.这时我们会想,能不能加载并运行插件Apk的Activity.答案当然是能,否则后续我们的研究就没意义了,但是想实现Act ...
- selenium的安装、报错和解决
selenium是的作用是模拟点击浏览器上的按钮,配合一个无头浏览器就可以快速解决一些前端需要加解密的功能. 第一步pip install selenium安装的第一步就是用pip把模块下载回来. ...
- MySQL数据库Group by分组之后再统计数目Count(*)与不分组直接统计数目的区别
简述问题“统计最新时刻处于某一状态的设备的数量” 1. 首先子查询结果,可以看到每个设备最新的状态信息 2.1 在子查询的基础上,对设备状态进行分组,进行统计每个状态的设备数量 2.1.1 可以看到处 ...