(allure报告定制)代码使用详解

1.allure常用方法:

 

2.@allure.severity用例的严重程度级别

blocker :中断缺陷、致命bug、数据丢失、系统奔溃。

critical:临界缺陷、严重bug功能为实现、功能错误、重复提交

normal:一般缺陷bug、条件查询有误、无响应

minor:次要用例级别,提示bug、颜色样式、字体排列错别字

trivial:轻微级别,轻微bug,必填项无提示。

3.allure.attach()添加附件

1)Allure报告中添加附件(html)

  • 语法:allure.attach(body, name, attachment_type, extension),参数解释:
    • body:要写入附件的内容(HTML 代码块)。
    • name:附件名字。
    • attachment_type:附件类型,是 allure.attachment_type 其中的一种。
    • extension:附件的扩展名。
  • allure.attach("""
                    <a href="/" data-auto-route="true"><img src="https://ceshiren.com/uploads/default/original/1X/809c63f904a37bc0c6f029bbaf4903c27f03ea8a.png" alt="测试人社区" id="site-logo" class="logo-big"></a>""",
                          name="添加html片段", attachment_type=allure.attachment_type.HTML, extension="html")
    allure.attach('''html代码块''', '附件是HTML类型', allure.attachment_type.HTML)

     

2)Allure报告中添加图片/视频附件

    • 语法:allure.attach.file(source, name, attachment_type, extension),参数解释:
      • source:文件路径,相当于传一个文件。
      • name:附件名字。
      • attachment_type:附件类型,是 allure.attachment_type 其中的一种。
      • extension:附件的扩展名。
allure.attach.file("/Users/may/Downloads/zz.jpg", name="截图name", attachment_type=allure.attachment_type.JPG, extension="jpg")

4. allure.title()测试用例标题

运行结果中,title标题会显示在story下方

 

5. 完整例子: 

import allure


@allure.epic('项目名称00,epic')
@allure.feature('测试模块,feature')  # 一般用在类上方
class TestAllureReport:
    @allure.title('测试用例标题00,title')
    @allure.story('测试成功,story')
    @allure.severity(allure.severity_level.CRITICAL)
    @allure.description('用例的描述,description')
    @allure.issue("输入缺陷管理系统的链接", name='bug链接issue')
    @allure.link("设置一个链接", name='链接名称link')
    @allure.testcase(url='测试用例地址', name='testcase测试用例name')
    def test_example(self):

        with allure.step("步骤1:执行某个操作"):
            # 这里执行某个操作,例如:
            result = 1 + 1

        with allure.step("步骤2:验证结果"):
            assert result == 2, "验证失败"

        allure.attach("""
                <a href="/" data-auto-route="true"><img src="https://ceshiren.com/uploads/default/original/1X/809c63f904a37bc0c6f029bbaf4903c27f03ea8a.png" alt="测试人社区" id="site-logo" class="logo-big"></a>""",
                      name="添加html片段", attachment_type=allure.attachment_type.HTML, extension="html")
        allure.attach('''html代码块''',
                      '附件是HTML类型',
                      allure.attachment_type.HTML)

        allure.attach.file("/Users/may/Downloads/zz.jpg", name="截图name", attachment_type=allure.attachment_type.JPG, extension="jpg")
 

主函数

# run.py
import pytest
import os


if __name__ == "__main__":
    pytest.main(["-s","./","--capture=sys"])   #--capture=sys会把报错的情况写进测试报告中
    os.system('allure generate report/result -o report/allure_html --clean')

6. 运行结果:

 

posted @ 2023-10-09 23:21  yimu-yimu  阅读(135)  评论(0编辑  收藏  举报