36-pytest-allure报告添加文本、截图信息

简介: 36-pytest-allure报告添加文本、截图信息

前言

  • 在测试过程中,可能遇到各种各样的问题,需要在关键的地方,附加文本、图片以及html网页,用来补充测试步骤或测试结果,下面一起来学习如何在allure报告中增加这些信吧。

支持添加的类型

class AttachmentType(Enum):
    def __init__(self, mime_type, extension):
        self.mime_type = mime_type
        self.extension = extension
    TEXT = ("text/plain", "txt")
    CSV = ("text/csv", "csv")
    TSV = ("text/tab-separated-values", "tsv")
    URI_LIST = ("text/uri-list", "uri")
    HTML = ("text/html", "html")
    XML = ("application/xml", "xml")
    JSON = ("application/json", "json")
    YAML = ("application/yaml", "yaml")
    PCAP = ("application/vnd.tcpdump.pcap", "pcap")
    PNG = ("image/png", "png")
    JPG = ("image/jpg", "jpg")
    SVG = ("image/svg-xml", "svg")
    GIF = ("image/gif", "gif")
    BMP = ("image/bmp", "bmp")
    TIFF = ("image/tiff", "tiff")
    MP4 = ("video/mp4", "mp4")
    OGG = ("video/ogg", "ogg")
    WEBM = ("video/webm", "webm")
    PDF = ("application/pdf", "pdf")

使用实例

# -*- coding: utf-8 -*-
# @Time    : 2022/9/11
# @Author  : 大海
import os
import allure
@allure.title('添加文本')
def test_attach_text():
    # 第一参数为添加的内容,name为展示的标题,attachment_type 是添加的类型
    allure.attach("大家好,我是测试小白!", name="纯文本", attachment_type=allure.attachment_type.TEXT)
@allure.title('添加HTML')
def test_attach_html():
    allure.attach("<body>大家好,我是测试小白! <a href='https://blog.csdn.net/IT_heima'>点击跳转博客</a></body>", name="html页面",
                  attachment_type=allure.attachment_type.HTML)
@allure.title('添加图片')
def test_attach_pic():
    allure.attach.file("..\study.jpg", name="图片", attachment_type=allure.attachment_type.PNG)
@allure.title('添加PDF')
def test_attach_pdf():
    allure.attach.file("..\pytest.pdf", name="PDF", attachment_type=allure.attachment_type.PDF)
if __name__ == '__main__':
    os.system('pytest -s test_68.py --alluredir=./allure-report --clear')
    # 打开allure报告 (目录与上面生成结果目录需一致)
    os.system('allure serve ./allure-report')

查看报告

相关文章
|
8天前
|
API
如何把自定义的函数,记录到你的Airtest报告里
如何把自定义的函数,记录到你的Airtest报告里
|
8天前
|
测试技术
Allure2添加用例标题、用例步骤
在Allure2报告中,可以通过`@allure.title`装饰器添加用例标题以增强可读性。标题可参数化或动态更新。同时,Allure2支持两种添加步骤方法:1) 使用`@allure.step`定义测试步骤并在用例中调用;2) 使用`with allure.step()`结构在代码块中添加步骤,提高测试流程的清晰度。这些功能提升了报告的易读性和测试的详细度。
12 3
|
8天前
|
运维 测试技术
实用指南:使用Pytest Allure测试框架添加用例失败截图
本文介绍了如何在使用`allure+pytest`进行软件测试时,通过`pytest_runtest_makereport`钩子函数自动捕获失败用例的截图。在`conftest.py`中定义钩子,当用例失败时,保存截图并附加到Allure测试报告中。测试代码示例展示了登录豆瓣的场景,测试失败时会自动生成截图。这种方法有助于快速理解和解决测试问题,提升测试效率和软件质量。
22 0
|
8天前
|
测试技术
测试报告需要包含哪些内容
测试报告需要包含哪些内容
|
10月前
|
测试技术
23-pytest-清空allure历史报告
23-pytest-清空allure历史报告
|
10月前
|
测试技术
25-pytest-参数化生成用例标题
25-pytest-参数化生成用例标题
25-pytest-参数化生成用例标题
|
测试技术
|
12月前
|
测试技术
测试报告的内容
1.测试的哪些功能模块(测试范围)2.测试用例执行情况(一共多少,执行了多少,未执行多少,通过多少,失败多少,用例失败率)3.发现的严重缺陷有哪些(仅仅罗列最严重级别的bug)4.测试结论(测试是否通过/是否满足发布要求/是否能够发布)5.下版本优化点和发版风险6.此次版本参与项目的产品测试研发人员
|
自然语言处理 Java 测试技术
pytest学习和使用21-测试报告插件allure-pytest如何使用?
pytest学习和使用21-测试报告插件allure-pytest如何使用?
126 0
pytest学习和使用21-测试报告插件allure-pytest如何使用?
|
测试技术
Pytest----allure报告定制样式
Pytest----allure报告定制样式
406 0
Pytest----allure报告定制样式

热门文章

最新文章