软件测试学习笔记丨Allure2 报告中添加附件-图片

本文介绍了在Allure2报告中添加图片附件的方法,包括使用Python的allure.attach或allure.attach.file()函数,并处理网络中断、图片大小限制及格式问题的解决方案。
摘要由CSDN通过智能技术生成

本文转自测试人社区,原文链接:https://ceshiren.com/t/topic/30191

  • Allure2 报告中添加附件-图片
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")
  • Allure2 报告中添加附件(图片)应用场景
    应用场景:在做 UI 自动化测试时,可以将页面截图,或者出错的页面进行截图,将截图添加到测试报告中展示,辅助定位问题。
    解决方案:
    Python:使用 allure.attach 或者 allure.attach.file() 添加图片。

  • Allure2 报告中添加附件(图片)- Python
    语法:allure.attach.file(source, name, attachment_type, extension)
    参数解释:
    source:文件路径,相当于传一个文件。
    name:附件名字。
    attachment_type:附件类型,是 allure.attachment_type 其中的一种(支持 PNG、JPG、BMP、GIF 等)。
    extension:附件的扩展名。
import allure

class TestWithAttach:
    def test_pic(self):
        allure.attach.file("pic.png",
                           name="图片",
                           attachment_type=allure.attachment_type.PNG,
                           extension="png")

语法:allure.attach(body, name=None, attachment_type=None, extension=None)
参数解释:
body:要写入附件的内容
name:附件名字。
attachment_type:附件类型,是 allure.attachment_type 其中的一种(支持 PNG、JPG、BMP、GIF 等)。
extension:附件的扩展名。

import allure

class TestWithAttach:
    def test_pic2(self):
        with open("./img/logo.png",mode="rb") as f :
            file = f.read()
            allure.attach(file,"页面截图",allure.attachment_type.PNG)
  • 裂图的原因以及解决办法
    图片上传过程中出现了网络中断或者传输过程中出现了错误。
    1、解决方案:重新上传图片。
    Allure 报告中的图片大小超过了 Allure 的限制。
    2、解决方案:调整图片大小。
    图片本身存在问题。
    3、解决方案:检查图片格式和文件本身。

获取更多软件测试知识

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值