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

本文档介绍了如何在Allure测试报告中添加各种类型的内容,包括文本、HTML、图片和PDF等,以丰富测试记录的详细信息。通过示例代码展示了如何使用allure库来实现这些功能,帮助测试人员更好地展示测试步骤和结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.youkuaiyun.com/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')

查看报告

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱学习de测试小白

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值