解读并加工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 ...
随机推荐
- windows程序设计00_HelloWorld
#include <windows.h> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR sz ...
- GlusterFS缺陷
glusterfs缺陷 转自:http://www.liuwq.com/2017/04/20/glusterfs%E8%AF%A6%E8%A7%A3/ glusterfs 原理.优势.使用范围等 Gl ...
- [问题记录]——log4net记录多个级别文件
目录 前言 Log4net 测试 小结 前言 不知不觉可都快又一年了,最近这段时间一直在忙着图形方面的东西(确实快给我搞死了),虽说时间还是相对有的,但是精力耗费的十有十一,把问题记录单开一栏,是为了 ...
- 【全栈修炼】OAuth2 修炼宝典
一.OAuth 概念 开放授权(OAuth)是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密的资源(如照片,视频,联系人列表),而无需将用户名和密码提供给第三方应用. -- 维基百 ...
- JS四种判断数据类型的方法:typeof、instanceof、constructor、Object.prototype.toString.call()
1.typeof 1 console.log(typeof ""); //string 2 console.log(typeof 1); //number 3 console.lo ...
- 【hibernate】映射继承关系
[hibernate]映射继承关系 转载:https://www.cnblogs.com/yangchongxing/p/10405151.html ========================= ...
- java8-Stream流API
一回顾与说明 经过前面发布的三章java8的博客,你就懂得了我们为什么要用Lamda表达式,Lamda表达式的原理与函数式接口的关系,从Lamda表达式到方法引用和构造引用. 想要学Stream流你必 ...
- 详解EMC测试国家标准GB/T 17626
电波暗室,用于模拟开阔场,同时用于辐射无线电骚扰(EMI)和辐射敏感度(EMS)测量的密闭屏蔽室. 来源:http://gememc.com/upload/201712/201712010930227 ...
- 从零开始学.net core(一)
https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.0
- mysql-magic 从dump中获取MySQL的明文密码
项目地址: https://github.com/hc0d3r/mysql-magic 安装: git clone --recurse-submodules https://github.com/hc ...