allure 测试报告

发布于 更新于
本文目录
  1. --allure-link-pattern=issue:http://www.mytesttracker.com/issue/{}

技术文章持续集成与运维

1、allure介绍 allure是一个轻量级,灵活的,支持多语言的测试报告工具 多平台的,奢华的report框架 可以为dev/qa提供详尽的测试报告、测试步骤、log 也可以为管理层提供high

1、allure介绍      allure是一个轻量级,灵活的,支持多语言的测试报告工具      多平台的,奢华的report框架      可以为dev/qa提供详尽的测试报告、测试步骤、log      也可以为管理层提供high level统计报告      Java语言开发,支持pytest,JaveScript, PHP, ruby等      可以集成到Jenkins

2、allure安装      (1) windows/mac通用安装方法                https://github.com/allure-framework/allure2/releases 下载allure2.7.zip包                解压->进入bin目录->运行allure.bat                把bin目录加入PATH环境变量      (2) Mac 可以使用brew安装                brew install allure      (3) 官网:http://allure.qatools.ru/      (4) 文档: https://docs.qameta.io/allure/#

3、使用allure2生成精美报告      (1) 安装allure-pytest插件                pip install allure-pytest      (2) 运行

![image.png](/images/upload/file/2023/01/image-bca46a83.png)

4、allure常用的特性      (1) 场景                希望在报告中看到测试功能,子功能或场景,测试步骤,包括测试附加信息      (2) 解决                @feature, @story, @step, @attach      (3) 步骤                import allure                功能上加@allure.feature(‘功能名称’)                子功能上加@allure.story(‘子功能名称’)                步骤上加@allure.step(‘步骤细节’)                @allure.attach(‘具体文本信息’),需要附加的信息,可以使数据,文本,图片,视频,网页                如果只测试登陆功能运行的时候可以加限制过滤:pytest 文件名 --allure-features ‘购物车功能’ --allure-stories ‘加入购物车’(注意这里—allure_features中间是下划线)

5、allure特性-feature/story       注解@allure.feature与@allure.store的关系           feature相当于一个功能,一个大的模块,将case分类到某个feature中,报告中behaviore中显示,相当于testsuite。           story相当于对应这个功能或者模块下的不同场景,分支功能,属于feature之下的结构,报告在features中显示,相当于testcase。           feature与story类似于父子关系

6、allure特性-step       测试过程中每个步骤,一般放在具体逻辑方法中       可以放在关键步骤中,在报告中显示       在app,web自动测试当中,建议每切到一个新的页面当做一个step       用法:             @allure.step(): 只能以装饰器的形式放在类或方法上面             with allure.step(): 可以放在测试用例方法里面,但测试步骤的代码需要被该语句包含

7、allure特性-issue,testcase       关联测试用例(可以直接给测试用例的地址链接)       关联bug            执行的时候需要几个参数              --allure-link-pattern=issue:http://www.mytesttracker.com/issue/{}       代码

@allure.issue('140', '这是一个issue') def test_with_issue_link(): pass 1 2 3 4 TEST_CASE_LINK = 'https://github.com/qameta/allure-integrations/issues/8#issuecomment-268313637' @allure.testcase(TEST_CASE_LINK, '登陆用例') def test_with_testcase_link(): print('这是一条测试用例的链接,链接到') pass 1 2 3 4 5 @allure.link("http://wwww.baidu.com", name="链接") def test_with_link(): print("这是一条加了链接的测试") pass 1 2 3 4 8、按重要性级别进行一定范围测试       场景             通常测试有P0、冒烟测试、验证上线测试。按重要性级别来分别执行的,比如上线要把主流程和重要模块都要跑一遍。       解决             通过附加pytest.mark标记             通过allure.feature,allure.story             也可以通过allure.severity来附加标记       级别             Trivial:不重要,Minor:不太重要,Normal:正常问题,Critical:严重,Blocker:阻塞

      步骤             在方法,函数和类上面加                   @allure.serverity(allure.serverity_level.TRIVIAL)             执行时                   pytest -s -v 文件名 --allure-serverities normal,critical

import allure

def test_with_no_severity_labe(): pass

@allure.severity(allure.severity_level.TRIVIAL) def test_with_trivial_severity(): pass

@allure.severity(allure.severity_level.NORMAL) def test_with_normal_severity(): pass

@allure.severity(allure.severity_level.NORMAL) class TestClassWithNormalSeverity(object):

def test_inside_the_normal_severity_test_class(self): pass

@allure.severity(allure.severity_level.CRITICAL) def test_inside_the_normal_severity_test_class_with_overriding_critcal_severity(self): pass 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22       配置pycharm

9、前端自动化测试——截图       场景             前端自动化测试经常需要附加图片或者html,在适当的地方,适当的时机截图       解决             @allure.attach显示许多不同类型的提供的附件,可以补充测试,步骤或测试结果。       步骤           在测试报告里附加网页:             allure.attach(body(内容),name,attachment_type,extension):             allure.attache(’首页’,‘这是错误页的结果信息’,allure.attachment_type.HTML)           在测试报告里附加图片:             allure.attach.file(source,name,attachment_type,extension):             allure.attach.file("./result/b.png",attachment_type=allure.attachment_type.PNG)

def test_inside_the_normal_severity_test_class_with_overriding_critcal_severity(self): allure.attach.file("./result/b.png", attachment_type=allure.attachment_type.PNG) pass 1 2 3 10、实战

来源:testingpai

继续阅读