selenium+python自动化91-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

原文地址:https://www.cnblogs.com/yoyoketang/p/8404204.html

时间: 2024-08-29 06:14:44

selenium+python自动化91-unittest多线程生成报告(BeautifulReport)的相关文章

selenium+python+unittest多线程生成报告(BeautifulReport)

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

python自动化--批量执行测试之生成报告

一.生成报告 1.先执行一个用例,并生成该用例的报告 # -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.common.except

selenium+python自动化98--文件下载弹窗处理(PyKeyboard)

前言 在web自动化下载操作时,有时候会弹出下载框,这种下载框不属于web的页面,是没办法去定位的(有些同学一说到点击,脑袋里面就是定位!定位!定位!) 有时候我们并不是非要去定位到这个按钮再去点击,学会使用键盘的快捷键操作,也能达到一样的效果. 之前讲过一篇Selenium2+python自动化75-非input文件上传(SendKeys)这个当时是基于python2写的. 最近很多小伙伴开始用python3了,这个SendKeys在python3上没法用,python3需要用PyUserIn

Pycharm+Selenium Python 自动化搭建

Pycharm+Selenium  自动化搭建 一,按照博客链接安装: (1)Pycharm+Selenium Python 自动化搭建 (2) 下载chrom对应版本chromdriver http://chromedriver.chromium.org/downloads (3)解压放在python37目录下 二,创建后代码 (1)代码: from selenium import webdriver options = webdriver.ChromeOptions() options.bi

selenium+python自动化81-html报告优化(饼图+失败重跑+兼容python2&3)【转载】

优化html报告 为了满足小伙伴的各种变态需求,为了装逼提升逼格,为了让报告更加高大上,测试报告做了以下优化: 测试报告中文显示,优化一些断言失败正文乱码问题 新增错误和失败截图,展示到html报告里 优化点击截图放大不清晰问题 增加饼图统计 失败后重试功能 兼容python2.x 和3.x 报告效果 1.生成的测试报告效果如下图,默认展示报错和异常的用例,失败重试的用例结果也会统计进去. 2.点击显示截图,可以直接显示截取的图片,无需保存到本地 table表格 1.修改表格的td后面内容,可以

【python-excel】Selenium+python自动化之读取Excel数据(xlrd)

Selenium2+python自动化之读取Excel数据(xlrd) 转载地址:http://www.cnblogs.com/lingzeng86/p/6793398.html ···························································································································

selenium+python自动化97--unittest参数化(paramunittest)

前言 paramunittest是unittest实现参数化的一个专门的模块,可以传入多组参数,自动生成多个用例 前面讲数据驱动的时候,用ddt可以解决多组数据传入,自动生成多个测试用例.本篇继续介绍另外一个参数化的框架paramunittest,也能实现一样的效果. 环境准备 1.先pip 下载安装 paramunittest pip install paramunittest 官方文档 1.官方文档地址:https://pypi.python.org/pypi/ParamUnittest/

Selenium+python自动化21-TXT数据参数化

前言      在17篇我们讲了excel数据的参数化,有人问了txt数据的参数化该怎么办呢,下面小编为你带你txt数据参数化的讲解 一.以百度搜索为例,自动搜索五次不同的关键字.输入的数据不同从而引起输出结果的变化. 测试脚本: 1 #coding=utf-8 2 from selenium import webdriver 3 import unittest, time, os 4 class Login(unittest.TestCase): 5 def test_login(self):

selenium+python自动化77-autoit文件上传【转载】

前言 关于非input文件上传,点上传按钮后,这个弹出的windows的控件了,已经跳出三界之外了,不属于selenium的管辖范围(selenium不是万能的,只能操作web上元素).autoit工具处理windows的控件窗口是专业的,所以这个需借助AutoIt来解决了. 一.环境准备 1.可以autoit官网上下载,安装 http://www.autoitscript.com/site/ 2.下载到本地后傻瓜式安装,安装完之后在应用程序找到这个Autoit v3 3.AutoIt里面几个菜