前言

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)的更多相关文章

  1. unittest多线程生成报告-----BeautifulReport

    原文地址https://www.cnblogs.com/yoyoketang/p/8404204.html 前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点, ...

  2. selenium+python自动化91-unittest多线程生成报告(BeautifulReport)

    前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了. 环境必备 ...

  3. selenium+python-unittest多线程生成报告

    前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了. 环境必备 ...

  4. Python-Unittest多线程生成报告

    前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了. 环境必备 ...

  5. unittest自动化测试举例:自动读取ymal用例&调用接口并生成报告

    用unittest框架写的接口自动化实现过程: 1.编写ymal格式用例: 2.导入ddt模块,该模块的主要功能是帮你读取ymal用例文件,自动获取内容并循环调用函数,具体见代码. 3.导入Beaut ...

  6. unittest框架,漂亮的报告BeautifulReport配置与错误截图详细解说

    1.下载BeautifulReport模块 下载地址:https://github.com/TesterlifeRaymond/BeautifulReport 2.解压与存放路径 下载Beautifu ...

  7. 『心善渊』Selenium3.0基础 — 29、使用HTMLTestRunner生成unittest的HTML报告

    目录 1.HTMLTestRunner介绍 2.HTMLTestRunner的使用 3.测试报告示例 4.封装成模块 1.HTMLTestRunner介绍 HTMLTestRunner是一个基于uni ...

  8. selenium,unittest——自动化执行多个py文件脚本并生成报告

    将多个py文件的自动化脚本顺序运行,并生成报告,运行run_all_case后会自动运行文件内所有test开头的py文件并在指定文件夹report生成由脚本时间命名的报告 脚本执行后结果: 生成报告并 ...

  9. day11_单元测试_读取yaml文件中的用例,自动获取多个yaml文件内容执行生成报告

    一.使用.yaml格式的文件直接可以存放字典类型数据,如下图,其中如果有-下一行有缩进代表这是个list,截图中是整体是一个list,其中有两部分,第二部分又包含另外一个list 二.单元测试:开发自 ...

随机推荐

  1. Lightoj 1025 - The Specials Menu (区间DP)

    题目链接: Lightoj 1025 - The Specials Menu 题目描述: 给出一个字符串,可以任意删除位置的字符,也可以删除任意多个.问能组成多少个回文串? 解题思路: 自从开始学dp ...

  2. 喵哈哈村的魔法考试 Round #3 (Div.2) ABCDE

    官方题解:http://www.cnblogs.com/qscqesze/p/6480284.html 哗啦啦村的刁难(1) 描述 哗啦啦村作为喵哈哈村的对头,于是他们准备给喵哈哈村一个好看. 哗啦啦 ...

  3. 暴力 BestCoder Round #41 1001 ZCC loves straight flush

    题目传送门 /* m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 ╰· */ #include <cstdio> #include < ...

  4. 1-3方法的重载(overload)

    之前已经写了一个方法sumInt用来计算两个int类型数字的和,如果要是想计算两个float类型数字的和呢?ok,那就再来写一个sumFloat方法,除此之外,还有long类型,double类型,如果 ...

  5. 正则表达式exec方法的陷阱

    http://www.w3school.com.cn/jsref/jsref_exec_regexp.asp exec() 方法的功能非常强大,它是一个通用的方法,而且使用起来也比 test() 方法 ...

  6. 与Cookie相比,Web Storage存在的优势

    与Cookie相比,Web Storage存在不少的优势,概括为以下几点:1. 存储空间更大:能提供5MB的存储空间(不同浏览器的提供的空间不同),Cookie仅4KB2. 存储内容不会发送到服务器: ...

  7. oracle 权限、规则

    Oracle中关于权限与规则简单总结: --1,管理员登录 conn sys/orcl@orcl as sysdba; --2,创建用户方案---必须管理员身份才能操作 create user use ...

  8. 复习-PEP8规范(转)

    PEP8 Python 编码规范 一 代码编排1 缩进.4个空格的缩进(编辑器都可以完成此功能),不使用Tap,更不能混合使用Tap和空格.2 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换 ...

  9. CF779C(round 402 div.2 C) Dishonest Sellers

    题意: Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last ...

  10. Android Studio3.0 Error:Execution failed for task ':app:javaPreCompileDebug' 错误

    Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be expli ...