selenium+python+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/jiachangwei/p/12154007.html

时间: 2024-08-29 13:45:56

selenium+python+unittest多线程生成报告(BeautifulReport)的相关文章

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

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

selenium+python+unittest:一个类中只执行一次setUpClass和tearDownClass里面的内容(可解决重复打开浏览器和关闭浏览器,或重复登录等问题)

unittest框架是python自带的,所以直接import unittest即可,定义测试类时,父类是unittest.TestCase. 可实现执行测试前置条件.测试后置条件,对比预期结果和实际结果,检查程序的状态,生成测试报告. 且断言的话unittest框架很方便. 在这主要记录下setUp()和tearDown()这两个的问题,每次执行一个测试用例(test开头的方法),就会执行一次setUp()和tearDown(), 导致执行多个测试用例时,会反复的打开浏览器操作,这个很浪费时间

selenium(python)用HTMLTestRunner导出报告(断言)信息的显示

导出报告如图所示,没有显示相关信息 修改HTMLTestRunner.py文件的763-768行,注释掉if else,保留else 的uo = o 再次运行可看到信息(测试用例中的print信息也会显示在测试报告中,断言错误信息也会显示) 当测试报告代码和测试用例分开编写时 ,在测试报告的控制台不会输出不在本窗口的print信息(多线程问题) 这只是记录下,没有什么实际的问题. 原文地址:https://www.cnblogs.com/may18/p/10456488.html

selenium+python unittest实践过程之问题杂集

1.列表选择项后直接获取文本内容获取不到,应该获取选择后显示的button的值 2.取值后的值带有空格,可以使用.strip()删除前后空格,以便断言 3.取值后有些值需要对类型进行转换才能断言成功 4.对于checkbox以及分页的遍历遇到的问题 每次勾选checkbox点击查询或者是点击页数按钮,页面都会刷新,webelement获取的元素过期,for循环的遍历失败 报错: Error: selenium.common.exceptions.StaleElementReferenceExce

【selenium+Python unittest】之发送邮箱时报错:smtplib.SMTPDataError、smtplib.SMTPAuthenticationError(例:126邮箱)

原代码如下: import smtplib from email.mime.text import MIMEText from email.header import Header #要发送的服务器 smtpserver = 'smtp.126.com' #要发送的邮箱用户名/密码 user = 'XXX@126.com' password = 'XXX' #发送的邮箱 sender = 'XXX@126.com' #接收的邮箱 receiver = 'XXX@qq.com' #发送邮箱主题 s

selenium + python自动化测试unittest框架学习(二)

1.unittest单元测试框架文件结构 unittest是python单元测试框架之一,unittest测试框架的主要文件结构: File >report >all_case.py >test_case >__init__.py >test_case1..... >public >__init__.py >login.py >loginout.py test_case文件夹主要存放测试用例,且测试用例命名以test_开头 public文件夹是test

Unittest+HTMLTestRunner不能生成报告解决方法和报告安装使用

1.问题现象 在使用HTMLTestRunner生成测试报告时,出现程序运行不报错,但不能生成报告的情况. 刚开始找了很久没发现问题,后来加上打印信息,发现根本没执行生成报告这部分代码.最后网上找到原因:pycharm 在运行测试用例的时候 默认是以unittest 框架来运行的,所以不能生成测试报告. 需要设置成不要用unittest框架运行: HTMLTestRunner.pyw文件经过修改的,需要下载:链接:https://pan.baidu.com/s/1BtF4Xus3kecI8qfT

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自动化测试unittest框架学习(一)selenium原理及应用

unittest框架的学习得益于虫师的<selenium+python自动化实践>这一书,该书讲得很详细,大家可以去看下,我也只学到一点点用于工作中,闲暇时记录下自己所学才能更加印象深刻.unittest框架学习需要掌握以下知识点: (1)Selenium原理及工具使用 (2)webdriver元素定位,id,name,class name,css seletor,xpath (3)python语言基础,模块,参数化,语言,装饰器 (4)unittest框架认识及学习:模块化,断言,参数化,数