https://www.jianshu.com/p/3d2c0e092ffb

自动化测试,最重要的还是测试报告,下面就教大家使用BeautifulReport生成自动化测试报告
GitHub:https://github.com/TesterlifeRaymond/BeautifulReport

第一步:安装git

1、下载地址:https://git-scm.com/downloads
2、安装:按照默认安装就完事了
3、环境配置:配置(Git安装目录)/Git/cmd完整路径到环境变量path下

 
配置环境变量
 
安装成功
第二步:安装BeautifulReport

1、cmd下进入到指定目录:(python3安装目录)\Lib\site-packages

 
指定目录
 
进入指定目录

2、复制BeautifulReport到指定目录

>>>git clone https://github.com/TesterlifeRaymond/BeautifulReport
 
复制BeautifulReport
 
复制完成
第三步:使用BeautifulReport生成报告
 
大概的一个目录

1、测试用例py:

# -*- coding: utf-8 -*-
import os
import time
import unittest
from selenium import webdriver
from dateutil.parser import parse
from BeautifulReport import BeautifulReport class Test(unittest.TestCase):
# 定义一个保存截图函数
def save_img(self, img_name):
self.browser.get_screenshot_as_file('{}/{}.png'.format(os.path.abspath("E:/test/auto_test_local/Auto_Test/img"), img_name))
# 启动函数,每个用例测试前,都会执行该函数
def setUp(self):
self.browser = webdriver.Chrome()
self.browser.set_window_size(1920, 1080)
self.starttime = parse(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print("开始测试时间:", self.starttime)
self.browser.get("https://www.baidu.com/")
time.sleep(3) # 结束函数,每个用例测试结束后,都会执行该函数
def tearDown(self):
time.sleep(3)
self.browser.quit()
self.endtime = parse(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print("测试结束时间:", self.endtime)
totaltime = (self.endtime - self.starttime).total_seconds()
print("总时长:", totaltime, "秒") # 测试用例1:必须以test_开头
@BeautifulReport.add_test_img('打开登录页面', '输入账号密码', '登录')
def test_01(self):
u"""登录"""
self.browser.find_element_by_xpath("//*[@id=\"u1\"]/a[7]").click()
# 需要进行截图的时候,直接调用截图函数就ok,下同
self.save_img('打开登录页面')
self.browser.find_element_by_xpath("//*[@id=\"TANGRAM__PSP_10__footerULoginBtn\"]").click()
# self.browser.find_element_by_id("TANGRAM__PSP_10__footerULoginBtn").click()
self.browser.find_element_by_id("TANGRAM__PSP_10__userName").send_keys("userName")
time.sleep(1)
self.browser.find_element_by_id("TANGRAM__PSP_10__password").send_keys("password")
time.sleep(1)
self.save_img('输入账号密码')
self.browser.find_element_by_id("TANGRAM__PSP_10__submit").click()
time.sleep(1)
self.save_img('登录') # 测试用例2:也是必须以test_开头
@BeautifulReport.add_test_img('测试用例2')
def test_02(self):
u"""测试用例2"""
self.save_img('测试用例2')
time.sleep(1) if __name__ == '__main__':
unittest.main()

2、整合测试用例py

# -*- coding: utf-8 -*-
import unittest
from BeautifulReport import BeautifulReport # 用例存放位置
test_case_path="E:/test/auto_test_local/Auto_Test/Test_Case"
# 测试报告存放位置
log_path='E:/test/auto_test_local/Auto_Test/Test_Result/Test_Report'
# 测试报告名称
filename='测试报告-百度'
#用例名称
description='百度登录'
# 需要执行哪些用例,如果目录下的全部,可以改为"*.py",如果是部分带test后缀的,可以改为"*test.py"
pattern="login_test.py" if __name__ == '__main__':
test_suite = unittest .defaultTestLoader.discover(test_case_path, pattern=pattern)
result = BeautifulReport(test_suite)
result.report(filename=filename,description=description,log_path=log_path)

3、执行测试:每次执行测试,只需要执行整合测试用例py就可以了

 
测试完成

4、测试报告展示:

 
测试报告

作者:车陂IT仔
链接:https://www.jianshu.com/p/3d2c0e092ffb
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

python3+selenium+BeautifulReport生成自动化测试报告的更多相关文章

  1. Python&Selenium&pytest借助allure生成自动化测试报告

    一.摘要 本篇博文将介绍Python和Selenium进行自动化测试时,如何借助allure生成自动化测试报告 二.环境配置 首先python环境中安装pytest和pytest_allure_ada ...

  2. Python&Selenium借助HTMLTestRunner生成自动化测试报告

    一.摘要 本篇博文介绍Python和Selenium进行自动化测试时,借助著名的HTMLTestRunner生成自动化测试报告 HTMLTestRunner.py百度很多,版本也很多,自行搜索下载放到 ...

  3. Python&Selenium借助html-testRunner生成自动化测试报告

    一.摘要 本博文将介绍Python和Selenium进行自动化测试时,借助html-testRunner 生成自动化测试报告 安装命令:pip install html-testRunner 二.测试 ...

  4. Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告1(使用IDLE)

    1.说明 自动化测试报告是一个很重要的测试数据,网上看了一下,使用HTMLTestRunner.py生成自动化测试报告使用的比较多,但是呢,小白刚刚入手,不太懂,看了很多博客,终于生成了一个测试报告, ...

  5. Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告2(使用PyCharm )

    1.说明 在我前一篇文件(Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告1(使用IDLE ))中简单的写明了,如何生产测试报告,但是使用IDLE很麻烦, ...

  6. python+selenium +unittest生成HTML测试报告

    python+selenium+HTMLTestRunner+unittest生成HTML测试报告 首先要准备HTMLTestRunner文件,官网的HTMLTestRunner是python2语法写 ...

  7. Python3和HTMLTestRunner生成html测试报告

    1.测试环境: Python3.5+unittest+HTMLTestRunner 2.下载HTMLTestRunner.py文件 下载地址 http://tungwaiyip.info/softwa ...

  8. python生成自动化测试报告并发送到指定邮箱

    #-*-coding:utf-8 -*- import HTMLTestRunner import unittest import time import sys import os import s ...

  9. selenium+Python(生成html测试报告)

    当自动化测试完成后,我们需要一份漂亮且通俗易懂的测试报告来展示自动化测试成果,仅仅一个简单的log文件是不够的 HTMLTestRunner是Python标准库unittest单元测试框架的一个扩展, ...

  10. mvn + testng + allure 生成自动化测试报告

    最近学了个新东西,使用java的testng测试框架做自动化测试.并且声称自动化报告. (1)创建maven工程 File-New-Other (2)创建testng类 当前import org.te ...

随机推荐

  1. nodejs mongoose连接mongodb报错,command find requires authentication

    MongoError: command find requires authentication at Connection.<anonymous> (/home/Map/node_mod ...

  2. windows10本地联调zk环境报异常SASL config status: Will not attempt to authenticate using SASL (unknown error)

    感谢原文:https://blog.csdn.net/qq_43639296/article/details/123282280 SASL config status: Will not attemp ...

  3. ES6-Class类上

    一.基础认知 构造方法有点类似构造函数,前面学的构造函数是模拟类的,ES6用类即可 不能直接调用Person()报错,和构造函数不同,构造函数不加new调用也不报错: 一般在constructor里面 ...

  4. mysql sum 聚合计算后精度不准 出现多位小数点后的数

    解决办法 原收款单money 字段 为 decimal(28,8) 经过层层计算用到了 @total := ( beginning + @total + gather - verification ) ...

  5. 【文献阅读】Automatic berthing for an underactuated unmanned surface vehicle: A real-time motion planning approach

    (1)文章工作 This paper presents Extended Dynamic Window Approach (EDWA) for the automatic berthing of an ...

  6. EBS 常用sql

    1)查看请求挂在哪个状态下 SELECT fcpv.concurrent_program_name FROM fnd_request_groups frg, --请求组 fnd_request_gro ...

  7. win11恢复完整右键菜单

    使用注册表修改 首先,通过修改注册表,我们就可以将 Win11 的右键菜单改为老样式.下面是具体的方法. 运行"regedit",开启注册表编辑器,定位到"HKEY_CU ...

  8. :)torch转onnx总结--|

    torch->onnx 参考:参考连接:https://blog.csdn.net/cxx654/article/details/123011332 1 安装 onnx >python - ...

  9. ubuntu系统更换源和apt命令参数

    一:问题概述 ubuntu,我们在使用apt新装软件的时候,会使用官方的网站去下载软件,但是会因为国内的转接点太多,而导致下载的速度非常慢 ,我们可以通过换成一些中间的节点来进行下载,比如阿里源,中科 ...

  10. C# 在GridView里面使用a标签下载文件(图片)

    不能使用ajax进行下载文件的操作,具体原因需百度 前端页面,在GridView里面使用模板列,模板列放a标签 <cimesui:cimesGridView ID="GridView1 ...