allure测试报告美化与定制
一份简单的测试报告
一份简单的测试报告可以使用pytest的插件html就可以生成, demo如下 先下载
pip install pytest-html
下载完之后,在当前执行过测试用例的测试目录下的终端执行
pytest --html=report.html # 即可生成一份简单的 report.html 报告, 如下图

allure介绍
allure 可以生成一个漂亮的测试报告。做kpi的时候老板看到可以加个鸡腿
allure安装
allure安装还是有点复杂的,首先是给到allure的下载路径 https://github.com/allure-framework/allure2/releases
下载完成之后,解压到本地电脑,这步没问题就要
把bin目录添加到环境变量Path下
bin目录

然后我的电脑右键属性 -> 高级设置 -> 环境变量path编辑

这步完成代表基本可以,但是电脑如果没有安装jdk的情况下,allure是运行不成功的。所以我们又要去安装一个jdk
安装jdk参考 https://blog.csdn.net/weixin_44535573/article/details/110232317
jdk安装完毕之后,就可以在终端中输入
allure --version

这样就可以使用allure服务了
pytest_allure 插件 Allure报告生成
安装完allure 如果需要在python中使用allure,则需要安装多一个库来操作allure
allure官方文档 参考:https://docs.qameta.io/allure/#_pytest
pip install allure-pytest —index-url https://pypi.douban.com/simple
参考官网的demo,生成一个简单的例子
新建一个文件
import pytest
def test_success():
"""this test succeeds"""
assert True
def test_failure():
"""this test fails"""
assert False
def test_skip():
"""this test is skipped"""
pytest.skip('for a reason!')
def test_broken():
raise Exception('oops')
if __name__ == '__main__':
pytest.main(["-s", "test_allure01.py"])
在该文件夹下创建多一个result文件夹,然后在终端执行命令
pytest .\test_allure01.py --alluredir=result/1 # 将文件生成在result下的1文件
生成成功后会有一批json的数据,这时候我们就可以用allure来执行这个文件夹
allure serve .\result\1\

还有一种方法是生成在本地的,有兴趣可以自行了解
allure 特性分析
场景:
- 希望在报告中看到测试功能,子功能或者场景,测试步骤 包括测试附加信息
解决: - @Feature, @story, @step, @attach
步骤: - import allure
- 功能上加 @allure.feature("功能名称")
- 子功能上加 @allure.story("子功能名称")
- 步骤上加 @allure.step("步骤细节")
- allure.attach("具体文本信息"), 需要附加的信息,可以是数据,文本,图片,视频,网页
新建一个文件demo
import pytest
import allure
@allure.feature("登录模块")
class TestLogin():
@allure.story("登录成功")
def test_login_success(self):
print("这是登录")
pass
@allure.story("登录失败")
def test_login_success_a(self):
print("这是登录")
pass
@allure.story("用户名缺失")
def test_login_success_b(self):
print("用户名缺失")
pass
@allure.story("密码缺失")
def test_login_failure(self):
with allure.step("点击用户名"):
print("输入用户名")
with allure.step("点击密码"):
print("输入密码")
with allure.step("点击登录之后登录失败"):
assert '1' == 1
print('登录失败')
pass
@allure.story("登录失败")
def test_login_failure_a(self):
print("这是登录")
pass
if __name__ == '__main__':
pytest.main()
然后用allure生成,看看生成的不同, 就知道用法的差别
如果有很多用例在,而只想运行一个模块用例的话, 那就运行
pytest .\test_allure02.py --allure-features '登录模块'
或者 只想执行某个模块下的story
pytest -v .\test_allure02.py --allure-stories '登录成功'
- feature相当于一个功能,一个大的模块,将case分类到某个feature中,story属于feature下的内容
- feature与story类似于父子关系
- @allure.step() 只能以装饰器的形式放在类或者方法上面,用于关键点
- @allure.severity(allure.severity_level.TRIVIAL) 这是allure的标记,执行时 pytest -s -v 文件名 --allure-severities normal, critical 这样就可以执行相关的优先级
- allure.attach()
allure + pytest + selenium实战
默认已经调好selenium
实战内容为通过selenium 搜索三个关键词然后截图放到allure中, 前端自动化测试 百度搜索功能实战演示
import allure
import pytest
from selenium import webdriver
import time
# chrome_options = webdriver.ChromeOptions()
@allure.testcase("##") # 默认连接到一个测试用例管理的地址
@allure.feature('百度搜索')
@pytest.mark.parametrize('test_data1', ['allure', 'unitest', 'pytest'])
def test_step_demo(test_data1):
with allure.step("打开百度网页"):
driver = webdriver.Chrome(r'D:\my_project\git_deve\development\python_work\chromedriver_win32\chromedriver.exe')
driver.get('http://www.baidu.com')
driver.maximize_window()
with allure.step(f"输入搜索词{test_data1}"):
driver.find_element_by_id('kw').send_keys(test_data1) # 找到百度的Kw, 然后输入你好世界
time.sleep(2)
driver.find_element_by_id('su').click()
time.sleep(2)
with allure.step("保存图片"):
driver.save_screenshot('./result/1/a.png')
allure.attach.file('./result/1/a.png', attachment_type=allure.attachment_type.PNG)
allure.attach('<head></head><body>首页</body>', 'Attach with HTML type', allure.attachment_type.HTML)
with allure.step("退出浏览器"):
driver.quit()
代码写完之后。然后执行
pytest .\test_baidudemo.py --alluredir=result/1
# 然后生成报告
allure serve .\result\1
可以再改写一下,不用连续的打开chrom
import allure
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
# chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222") # 指定配置好的 chrom
# chrome_driver = r"E:\\chromedriver.exe" # 驱动路径
# driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options) # 加入驱动设置
# chrome_options = webdriver.ChromeOptions()
@allure.testcase("##") # 默认连接到一个测试用例管理的地址
@allure.feature('百度搜索')
@pytest.mark.parametrize('test_data1', ['allure', 'unitest', 'pytest'])
def test_step_demo(test_data1):
with allure.step("打开百度网页"):
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222") # 指定配置好的 chrom
chrome_driver = r"D:\my_project\git_deve\development\python_work\chromedriver_win32\chromedriver.exe" # 驱动路径
driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options) # 加入驱动设置
driver.get('http://www.baidu.com')
driver.maximize_window()
with allure.step(f"输入搜索词{test_data1}"):
driver.find_element_by_id('kw').send_keys(test_data1) # 找到百度的Kw, 然后输入你好世界
time.sleep(2)
driver.find_element_by_id('su').click()
time.sleep(2)
with allure.step("保存图片"):
driver.save_screenshot('./result/1/a.png')
allure.attach.file('./result/1/a.png', attachment_type=allure.attachment_type.PNG)
allure.attach('<head></head><body>首页</body>', 'Attach with HTML type', allure.attachment_type.HTML)
with allure.step("退出浏览器"):
driver.quit()
完。
allure测试报告美化与定制的更多相关文章
- allure测试报告
首先如果你没有安装 pytest 库的话,先使用 pip 安装一下: pip install pytest 另外还需要安装 pytest 支持 allure 报告的插件库: pip install a ...
- Python2 HTMLTestRunner自动化测试报告美化
python2 的测试报告美化,需要的同学直接用 #coding=utf-8 """ A TestRunner for use with the Python unit ...
- Jenkins集成allure测试报告
前言 Allure框架是一个功能强大的自动化测试报告工具,不仅支持多种编程语言,而且能够完美的与各种集成工具结合,包括Jenkins,TeamCity,Bamboo,Maven等等,因此受到了很多测试 ...
- Ubuntu全方位美化,定制教程
Ubuntu全方位美化,定制教程 上一篇随笔聊了聊Linux图形界面的各种名词及其关系,解释了何为xserver,何为xclient,linux的图形界面是如何工作的,Linux图形软件的多样性.li ...
- Allure测试报告完整学习笔记
目录 简介 安装Allure Allure测试报告的结构 Java TestNG集成Allure Report Python Pytest集成Allure Report 简介 假如你想让测试报告变得漂 ...
- HTMLTestRunner测试报告美化
前言 最近小伙伴们在学玩python,,看着那HTMLTestRunner生成的测试报告,左右看不顺眼,终觉得太丑.搜索了一圈没有找到合适的美化报告,于是忍不住自已动手进行了修改,因习惯python ...
- Pytest单元测试框架-allure测试报告
Allure Test Report 对于不同的编程语言,有很多很酷的测试框架.不幸的是,它们中只有少数能够提供测试执行输出的良好表示.Qameta软件测试团队正在致力于Allure--一个开源框架, ...
- TestNG测试报告美化
因TestNG自带的测试报告不太美观,可以使用testng-xslt进行美化 1.下载testng-xslt包 2.把/src/main/resources/TestNG-results.xsl放到你 ...
- java TestNG测试报告美化
测试报告 执行完测试用例之后,会在项目的test-output(默认目录)下生成测试报告 打开index.html文件,测试结果摘要,包括:套件名.测试用例成功数.测试用例失败数.测试用例忽略数和te ...
- Python3 HTMLTestRunner自动化测试报告美化
# FileName : MyHTMLTestRunner.py # Author : wangyinghao # DateTime : 2019/1/9 21:04 # SoftWare : PyC ...
随机推荐
- 在.net core中开发web页面,更新html代码刷新不生效的问题
因为在.net core之后的版本,程序都是以控制台应用程序的方式存在,所以一些老的项目升级后,会出现这样的情况, 解决方法,在nuget中引入 Microsoft.AspNetCore.Mvc.Ra ...
- appium自动化时,automatic server里面desired capabilities的json representation设置
一点一点来,记号下: 大体格式如下: { "platformName": "Android", "platformVersion": &qu ...
- Linux提权-权限升级
特权升级是一段旅程.没有灵丹妙药,很大程度上取决于目标系统的具体配置.内核版本.已安装的应用程序.支持的编程语言.其他用户的密码是影响您通往 root shell 之路的几个关键因素 什么是特权升级? ...
- 顺应潮流,解放双手,让ChatGPT不废话直接帮忙编写可融入业务可运行的程序代码(Python3.10实现)
众所周知,ChatGPT可以帮助研发人员编写或者Debug程序代码,但是在执行过程中,ChatGPT会将程序代码的一些相关文字解释和代码段混合着返回,如此,研发人员还需要自己进行编辑和粘贴操作,效率上 ...
- Jan Ozer:高清直播互动场景下的硬编码如何选型?
前言 高清直播逐渐普及,硬编码也成为大势所趋.在 RTE 2022 大会上,来自 NETINT 的 Jan Ozer 通过一系列的对比测试结果,详细分享了如何为高清直播互动场景进行硬编码的技术选型. ...
- 20个值得收藏的实用JavaScript技巧
1.确定对象的数据类型 function myType(type) { return Object.prototype.toString.call(type).slice(8, -1); 使用Obje ...
- TCC 分布式事务解决方案
更多内容,前往 IT-BLOG 一.什么是 TCC事务 TCC 是Try.Confirm.Cancel三个词语的缩写,TCC要求每个分支事务实现三个操作:预处理Try.确认Confirm.撤销Canc ...
- 迁移学习(PCL)《PCL: Proxy-based Contrastive Learning for Domain Generalization》
论文信息 论文标题:PCL: Proxy-based Contrastive Learning for Domain Generalization论文作者:论文来源:论文地址:download 论文代 ...
- GO实现Redis:GO实现Redis的AOF持久化(4)
将用户发来的指令以RESP协议的形式存储在本地的AOF文件,重启Redis后执行此文件恢复数据 https://github.com/csgopher/go-redis 本文涉及以下文件: redis ...
- Windows服务器高物理内存占用问题排察
我经常在手中拿着一个内存条手链,以彰显我是计算机深入挖掘专家,它就是一个象征,类似摸金符,有它代表你有资格可以探墓了. 同事找到我说:"我们有一台服务器,内存资源持续高位运行,经常浮动在80 ...