本文转自测试人社区,原文链接:https://ceshiren.com/t/topic/30192
Allure2 报告中添加附件(html)应用场景
- 应用场景:可以定制测试报告页面效果,可以将 HTML 类型的附件显示在报告页面上。
解决方案:
Python:使用
allure.attach()
添加 html 代码。
语法:allure.attach(body, name, attachment_type, extension)
参数解释:
- body:要写入附件的内容(HTML 代码块)。
- name:附件名字。
- attachment_type:附件类型,是
allure.attachment_type
其中的一种。 - extension:附件的扩展名。
class TestWithAttach:
def test_html(self):
allure.attach('<head></head><body> a page </body>',
'附件是HTML类型',
allure.attachment_type.HTML)
def test_html_part(self):
allure.attach('''html代码块''',
'附件是HTML类型',
allure.attachment_type.HTML)