unittest多线程生成报告(BeautifulReport)
前言
selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了。
环境必备:
- python3.6 : BeautifulReport不支持2.7
- tomorrow : pip install tomorrow安装
- BeautifulReport : github下载后放到/Lib/site-packages/目录下
BeautifulReport
1.BeautifulReport下载地址:BeautifulReport
2.下载方法:
- 方法一 会使用git的直接用git下载到本地
git clone https://github.com/TesterlifeRaymond/BeautifulReport

- 方法二 点Clone or Download按钮,Download ZIP就能下载到本地了

3.下载完之后,把BeautifulReport整个包放到python的/Lib/site-packages/目录下

使用方法
1.项目结构:
case test开头的.py用例脚本
report 放生成的html报告
run_all.py 用于执行全部脚本

2.单个测试脚本test_a.py参考
# coding:utf-8
import unittest
from selenium import webdriver
import time
class Testaa(unittest.TestCase):
u'''测试用例a的集合'''
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Firefox()
def setUp(self):
self.driver.get("https://www.cnblogs.com/yoyoketang/")
def test_01(self):
u'''用例1:用例1的操作步骤'''
t = self.driver.title
print(t)
self.assertIn("悠悠", t)
def test_02(self):
u'''用例2:用例2的操作步骤'''
t = self.driver.title
print(t)
self.assertIn("悠悠", t)
def test_03(self):
u'''用例3:用例3的操作步骤'''
t = self.driver.title
print(t)
self.assertIn("悠悠", t)
@classmethod
def tearDownClass(cls):
cls.driver.quit()
if __name__ == "__main__":
unittest.main()
3.run_all代码
# coding=utf-8
import unittest
from BeautifulReport import BeautifulReport
import os
from tomorrow import threads
# 获取路径
curpath = os.path.dirname(os.path.realpath(__file__))
casepath = os.path.join(curpath, "case")
if not os.path.exists(casepath):
print("测试用例需放到‘case’文件目录下")
os.mkdir(casepath)
reportpath = os.path.join(curpath, "report")
if not os.path.exists(reportpath): os.mkdir(reportpath)
def add_case(case_path=casepath, rule="test*.py"):
'''加载所有的测试用例'''
discover = unittest.defaultTestLoader.discover(case_path,
pattern=rule,
top_level_dir=None)
return discover
@threads(3)
def run(test_suit):
result = BeautifulReport(test_suit)
result.report(filename='report.html', description='测试deafult报告', log_path='report')
if __name__ == "__main__":
# 用例集合
cases = add_case()
print(cases)
for i in cases:
print(i)
run(i)
4.报告效果图

备注:BeautifulReport是某大神在github分享的框架,这里借花献佛了,更多使用方法参考地址:https://github.com/TesterlifeRaymond/BeautifulReport
unittest多线程生成报告(BeautifulReport)的更多相关文章
- unittest多线程生成报告-----BeautifulReport
原文地址https://www.cnblogs.com/yoyoketang/p/8404204.html 前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点, ...
- selenium+python自动化91-unittest多线程生成报告(BeautifulReport)
前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了. 环境必备 ...
- selenium+python-unittest多线程生成报告
前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了. 环境必备 ...
- Python-Unittest多线程生成报告
前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了. 环境必备 ...
- unittest自动化测试举例:自动读取ymal用例&调用接口并生成报告
用unittest框架写的接口自动化实现过程: 1.编写ymal格式用例: 2.导入ddt模块,该模块的主要功能是帮你读取ymal用例文件,自动获取内容并循环调用函数,具体见代码. 3.导入Beaut ...
- unittest框架,漂亮的报告BeautifulReport配置与错误截图详细解说
1.下载BeautifulReport模块 下载地址:https://github.com/TesterlifeRaymond/BeautifulReport 2.解压与存放路径 下载Beautifu ...
- 『心善渊』Selenium3.0基础 — 29、使用HTMLTestRunner生成unittest的HTML报告
目录 1.HTMLTestRunner介绍 2.HTMLTestRunner的使用 3.测试报告示例 4.封装成模块 1.HTMLTestRunner介绍 HTMLTestRunner是一个基于uni ...
- selenium,unittest——自动化执行多个py文件脚本并生成报告
将多个py文件的自动化脚本顺序运行,并生成报告,运行run_all_case后会自动运行文件内所有test开头的py文件并在指定文件夹report生成由脚本时间命名的报告 脚本执行后结果: 生成报告并 ...
- day11_单元测试_读取yaml文件中的用例,自动获取多个yaml文件内容执行生成报告
一.使用.yaml格式的文件直接可以存放字典类型数据,如下图,其中如果有-下一行有缩进代表这是个list,截图中是整体是一个list,其中有两部分,第二部分又包含另外一个list 二.单元测试:开发自 ...
随机推荐
- 514 Freedom Trail 自由之路
详见:https://leetcode.com/problems/freedom-trail/description/ C++: class Solution { public: int findRo ...
- js数据类型之判断
js有几种类型,具体是:字符串(String).数字(Number).布尔(Boolean).数组(Array).对象(Object).空(Null).未定义(Undefined). js提供了typ ...
- mvc报( 检测到有潜在危险的 request.form 值 )错的解决方案
今天在做项目中遇到了报( 检测到有潜在危险的 request.form 值 )错,百度过后解决了该问题,出此问题主要还是因为提交的Form中有HTML字符串,例如你在TextBox中输入了html标签 ...
- Ubuntu rar的坑
通过apt-get安装rar后,执行rar命令会有如下坑: rar: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (si ...
- String 截取字符串#中间的文本
通过正则实现: String regex = "#([^#]+)#"; @Test public void test() { String text = "#中俄建交七十 ...
- Android RxJava小结
一.如何使用 在build.gradle中添加依赖 dependencies { api 'io.reactivex:rxandroid:1.2.1' api 'io.reactivex:rxjava ...
- 如何查看安装的java是32位的,还是64位的
命令 java -d32 -version 或者 java -d64 -version
- sprintf使用时需要注意的问题
- JavaScript 的垃圾回收与内存泄露
JavaScript采用垃圾自动回收机制,运行时环境会自动清理不再使用的内存,因此javascript无需像C++等语言一样手动释放无用内存. 在这之前先说一下垃圾回收的两种方式:引用计数与标记清除. ...
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'needDao' defined in URL
这个是我修改过后的mapper,是我的mapper中的空间地址写错了呢