首页 > 其他分享 >Allure使用教程 - 官方文档汉化

Allure使用教程 - 官方文档汉化

时间:2023-07-01 17:22:36浏览次数:41  
标签:教程 allure title -- 用例 Allure 文档 test def

Allure测试报告

目录

安装

Linux

对于基于 debian 的存储库,提供了 PPA

sudo apt-add-repository ppa:qameta/allure
sudo apt-get update 
sudo apt-get install allure

Mac OS X

对于 Mas OS,可通过 Homebrew 进行自动安装

brew install allure

Windows

对于Windows,Allure可以从Scoop命令行安装程序获得。

要安装 Allure,请下载并安装 Scoop,然后在 Powershell 中执行:

scoop install allure

此外,Scoop能够更新Allure分发装置。为此,请导航到 Scoop 安装目录并执行

\bin\checkver.ps1 allure -u

这将检查较新版本的 Allure,并更新清单文件。然后执行

scoop update allure

以安装较新版本。( 文档)

手动下载&安装

  1. Maven Central下载最新版本作为zip存档。
  2. 将归档文件解压到allure-commandline目录。
  3. 进入bin目录。
  4. 在Windows平台上使用allure.bat,在其他Unix平台上使用allure。
  5. 将allure 添加到系统PATH。

image-20230630125917536

  1. 检查安装:allure --version

image-20230630130047629

安装pytest-allure插件

pip3 install allure-pytest -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

快速入门

Allure监听器在测试执行期间会自动收集结果,只需添加alluredir选项,并选择输出的文件路径即可。

# 运行测试用例
pytest --alluredir=path

image-20230630173811937image-20230630173824082

测试完毕后,需要使用Allure命令行来让测试结果生成HTML报告:

# 方式1:在系统默认目录下生成测试报告,并打开
allure serve path

# 方式2:在指定目录下生成测试报告,使用open打开
allure generate “存储结果的path” -c -o  “在path生成html报告”
allure open “在path生成html报告”

实际栗子:

# 执行测试用例
>>> pytest -v --alluredir=C:\Users\houjingang\PycharmProjects\接口自动化测试\report\20230630
============================== test session starts ========================
platform win32 -- Python 3.7.4, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- e:\a_python37\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\houjingang\PycharmProjects\接口自动化测试
plugins: allure-pytest-2.9.45
collected 4 items                                                                                                                                                                                                                                      

run_test.py::TestMain::test_cases[C:\\case\\demo.yaml] PASSED                                                                                          [ 25%]
run_test.py::TestMain::test_cases[C:\\case\\LS_login.yaml] PASSED                                                                                      [ 50%]
run_test.py::TestMain::test_cases[C:\\case\\LS_login_01.yaml] PASSED                                                                                   [ 75%]
run_test.py::TestMain::test_cases[C:\\case\\LS_uploadFile_01.yaml] PASSED                                                                              [100%]

================================= 4 passed in 5.93s =========================

# 根据allure数据,生成html测试报告
>>> allure generate C:\Users\houjingang\PycharmProjects\接口自动化测试\report\20230630 -c -o C:\Users\houjingang\PycharmProjects\接口自动化测试\report\20230630-report  --clean
Report successfully generated to C:\Users\houjingang\PycharmProjects\接口自动化测试\report\20230630-report
    
>>> allure open  C:\Users\houjingang\PycharmProjects\接口自动化测试\report\20230630-report
Starting web server...
2023-07-01 13:58:07.191:INFO::main: Logging initialized @271ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://192.168.219.1:60088/>. Press <Ctrl+C> to exit

ps:下图所示,打开html报告是没有数据的。就需要注意generate 两个path参数,是不是使用错误了~

image-20230701140933935

allure特性

image-20230630175440478

可以在html报告中,添加用例描述、附件等信息,比如:

1、@allure.feature(功能名称)
@allure.feature("功能名称")
def test_with_a_title():
    pass
image-20230701170746648
2、@allure.story(子功能名称 )
@allure.story(’子功能名称‘)
def test_with_a_title():
    pass
image-20230701170737067
3、@allure.title(测试标题)
@allure.title("这是标题")
def test_with_a_title():
    pass

报告:

image-20230701160028855

与@allure.step一样,也支持位置参数 关键字参数

@allure.title("Parameterized test title: adding {param1} with {param2}")
@pytest.mark.parametrize('param1,param2,expected', [
    (2, 2, 4),
    (1, 2, 5)
])
def test_with_parameterized_title(param1, param2, expected):
    assert param1 + param2 == expected

也支持在测试主体中,动态更新标题

@allure.title("This title will be replaced in a test body")
def test_with_dynamic_title():
    assert 2 + 2 == 4
    allure.dynamic.title('更新标题')
4、@allure.description(用例描述)
@allure.description("用例描述")
def test_description_from_decorator():
    assert 42 == int(6 * 7)

栗子:

image-20230701155605525

另外,还可以在测试主体内部,动态更新描述。

@allure.description("用例描述")
def test_dynamic_description():
    assert 42 == int(6 * 7)
    allure.dynamic.description('更新了用例描述')
5、@allure.step(步骤)
# 方式1:
        
@allure.step(‘步骤’) 
def test_step():
    pass
# 方式2
def test_step():
    with allure.step(“步骤”):
    	pass
# 方式3
@allure.step	# 测试步骤为def函数名称
def test_step():
    pass

另外,step还支持形参的位置参数关键字参数。关键字参数的默认参数也会被捕获。

@allure.step('positional: "{0}", keyword: "{key}"')
def step_with_title_placeholders(arg1, key=None):
    pass

栗子:

6、@allure.attach(‘附件’)

allure还可以显示许多不同类型的附件,这些附件可以补充测试、步骤或fixture的结果。

# 方式1:

allure.attach(body, name, attachment_type, extension)

# body : 要写入文件的原始内容。
# name : 字符串
# attachment_type : 值 (allure.attachment_type 之一)
# extension : 提供将用作创建文件的扩展名。

栗子:

# 1、将open的文件,作为boby
with open(文件.html) as file:
    file_html = file.read()
allure.attach(file_html, "名字", attachment_type, extension)

# 2、将原始内容,作为boby
allure.attach('<head></head><body> a page </body>', 'Attach with HTML type', allure.attachment_type.HTML)
image-20230701153003282
# 方式2:
allure.attach.file(source, name, attachment_type, extension)

# source : 文件路径
# 其他参数与方式1相同

栗子:

def test_multiple_attachments():
    allure.attach.file('./data/totally_open_source_kitten.png', attachment_type=allure.attachment_type.PNG)
image-20230701152915066
7、@allure.severity(用例等级)
@allure.severity(严重等级)
def test_with_trivial_severity():
    pass

# 严重等级:
# allure.severity_level.Blocker
# allure.severity_level.CRITICAL
# allure.severity_level.NORMAL
# allure.severity_level.Minor
# allure.severity_level.TRIVIAL

执行不同等级的用例:

pytest --allure-severities normal,critical

报告:

image-20230701165032281

为了将报告与缺陷跟踪器或测试管理系统集成,Allure提供了@allure.link、@allure.issue和@allure.testcase描述符。

1、@allure.issue(缺陷链接)

将缺陷ID 作为输入参数,将其与问题链接类型的提供的链接模板一起使用。链接模板在 Pytest 的配置选项中 --allure-link-pattern 指定。链接模板和类型必须使用冒号指定:

# 1、当缺陷链接为:http://www.mytesttracker.com/issue/140

# 2、编写用例时,需要将issue id作为输入参数
@allure.issue('140', '缺陷描述')
def test_with_issue_link():
    pass

# 3、在执行pytest时,要携带参数
	--allure-link-pattern=issue:http://www.mytesttracker.com/issue/{}


同时类似的链接,也可以使用这种方式。

报告:

image-20230701162732148
2、@allure.testcase(用例链接)
@allure.testcase("用例连接", '测试用例标题')
def test_with_testcase_link():
    pass
image-20230701162857988
3、@allure.link(网址)
@allure.link("网址", name='Click me')
def test_with_named_link():
    pass
image-20230701162600669

帮助 --help

image-20230630181332352

image-20230630181311123

标签:教程,allure,title,--,用例,Allure,文档,test,def
From: https://www.cnblogs.com/struggleMan/p/17519562.html

相关文章

  • IDEA 2019 java开发工具软件安装教程
    IDEA全称IntelliJIDEA,是java编程语言开发的集成环境。IntelliJ在业界被公认为最好的java开发工具,尤其在智能代码助手、代码自动提示、重构、J2EE支持、各类版本工具(git、svn等)、JUnit、CVS整合、代码分析、创新的GUI设计等方面的功能可以说是超常的。软件介绍析您的代码,查找......
  • 传奇脚本教程:传奇定时刷怪活动脚本分享
    爱玩传奇的GM朋友对游戏中出现的活动或者地图里的怪物应该不陌生,在某个时间段就出现一个公告,或者在游戏介绍里就有,什么时间,什么地点,出现什么怪物,可以获得什么奖励今天我给你们分享定时刷怪的活动脚本,希望可以帮助到你这种活动大部分都是由机器人脚本(机器人配置解析)控制的首先,我们打......
  • Ubuntu虚拟机教程
    1.下载ubuntu镜像可以去中科大镜像站下载(本次下载20.04版本,不同版本操作会有差异,建议保持一致)https://mirrors.ustc.edu.cn/点击如图所示的按钮下载2.vmware配置安装虚拟机选择自定义,选择典型有几率会开不开机,且安装缓慢选择稍后安装,不然跟选择典型没有什么区别选择不使......
  • Ryu控制器教程
    RYU不要使用apt的方法安装,这样的安装是不完整的,并且相关文件不易查找。1.下载ryu源码cdcdDesktopgitclonehttps://gitee.com/lpm-123/ryu2.安装RYU环境安装PIPcdryupipinstall-rpip-requirements.txt-ihttps://pypi.tuna.tsinghua.edu.cn/simple安装依......
  • Mininet教程
    mininet的安装1.前言1、本次安装环境为ubuntu20.04。2、mininet为github上的最新版,我已经修改镜像地址并克隆到了gitee,只需要从我的gitee仓库克隆即可。3、mininet安装中需要自动使用apt安装额外依赖,为了确保稳定性,需要对ubuntu进行换源(按照ubuntu教程即可)。2.克隆minine......
  • sFlow-RT监控设备教程
    1.前言sflow-rt网站国内无法访问,这里使用蓝奏云下载2.下载源码https://lvpeiming.lanzoup.com/imRxy10was0h密码:5rxk3.开启sFlow-RT下载完毕之后,放入ubuntu并解压。sFlow-RT需要java环境,需要先配置java环境才能够运行。sudoapt-getinstallopenjdk-8-jdkjava环境安......
  • 离线安装ffmpeg源码包【详细教程】
    今天分享一下ffmpeg源码包的安装过程,针对在没有网络环境下,且不能直接使用yum如何成功安装ffmpeg源码包。博主本人通过正式服务器测试,记录整个安装过程。值得大家收藏同时,我会分享一下如何使用ffmpeg对H.264格式视频(MP4)进行m3u8+ts切片的转换,并生成m3u8+ts格式文件ffmpeg所需要环......
  • Redis Desktop Manager(Redis可视化工具)安装及使用教程
    RedisDesktopManager(Redis可视化工具)安装及使用教程2、一、工具/材料官网下载:https://redisdesktop.com/download百度网盘:https://pan.baidu.com/s/15xVRpCT8mkP2uT8PoBHT3g提取码:v727二、方法/步骤1.说明RedisDesktopManager是一款简单快速、跨平台的Redis桌面管理工具,也被......
  • 用C#实现在Word文档中搜索文本
    在word应用程序中搜索和替换文本是举手之劳的事情,通过word的对象模型,我们也可以使用编程方式来实现。Word的对象模型有比较详细的帮助文档,放在Office安装程序目录,office2003是在ProgramFiles\MicrosoftOffice\OFFICE11\2052下,文档本身是为VBA提供的,在这个目录下还可以......
  • 内核文档翻译 —— Building External Modules(编译外部模块)
    原文:https://www.kernel.org/doc/html/latest/kbuild/modules.htmlThisdocumentdescribeshowtobuildanout-of-treekernelmodule.1.Introduction"kbuild"isthebuildsystemusedbytheLinuxkernel.Modulesmustusekbuildtostaycompatiblewi......