解读并加工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 ...
随机推荐
- Dubbo源码分析之SPI(三)
一.概述 本篇介绍自适应扩展,方法getAdaptiveExtension()的实现.ExtensionLoader类本身很多功能也使用到了自适应扩展.包括ExtensionFactory扩展. 通俗 ...
- IDEA+Maven 整合SSM框架实现简单的增删改查(新手入门,傻瓜操作)
原博客地址:https://blog.csdn.net/khxu666/article/details/79851070 选用SSM框架的原因在目前的企业级Java应用中,Spring框架是必须的.S ...
- 快速失败(fail-fast)和安全失败(fail-safe)的区别是什么?
一:快速失败(fail—fast) 在用迭代器遍历一个集合对象时,如果遍历过程中对集合对象的内容进行了修改(增加.删除.修改),则会抛出Concurrent Modification Exceptio ...
- flutter学习之环境配置
1.Android SDK通常目录: 用户->用户名->AppData->Local=>Android->Sdk 2.不知道的情况下,打开Android Studio,然 ...
- Python 分析电影《南方车站的聚会》
<南方车站的聚会>由刁亦男执导,主要演员包括:胡歌.桂纶镁.廖凡.万茜等,该片于 2019 年 5 月 18 在戛纳电影节首映,2019 年 12 月 6 日在中国正式上映.故事灵感来自真 ...
- 调用高德API,通过输入的地址,如省份、市、区获取经纬度 ,通过输入的经纬度,获取区域详情
一.pom <?xml version="1.0" encoding="UTF-8"?><projectxmlns="http:// ...
- Android动态添加碎片
我们编写一个能够用过按钮动态更替碎片的APP,首先在主页上显示第一个碎片,点击按钮后可以替换到第二个碎片,或者删除已经替换掉的第二个碎片. 一.MainActivity.java import and ...
- Linux MySQL的root无法登录数据库ERROR 1045 (28000)
Linux环境下,脚本自动安装完数据库,命令行用mysql -uroot -ppasswaord 登录却报了这么个错: ERROR 1045 (28000): Access denied for us ...
- linux 系统账户 和 普通账户 的区别
最近使用 useradd -r 选项进行创建账户,用于测试,对-r 选项不是很明白,下面记录一些调研的过程: -r, --system Create a system account. System ...
- linux(center OS7)安装JDK、tomcat、mysql 搭建java web项目运行环境
一.安装JDK 1.卸载旧版本或者系统自带的JDK (1)列出所有已安装的JDK rpm -qa | grep jdk (2)卸载不需要的JDK yum -y remove 安装包名称 2.下载并解压 ...