本文共 1239 字,大约阅读时间需要 4 分钟。
@allure.step 是用于在测试用例中记录详细操作步骤的标记。它可以帮助生成更全面的测试报告。
@allure.step("步骤描述") import allure@allure.step("打开网站首页")def open(): pass@allure.step("输入账号、密码")def input_UsernameAndPassWord(): sendAndClickLogin("xiaoqiang", "1")@allure.step("输入账号、密码{arg1},{arg2},并点击登录")def sendAndClickLogin(arg1, arg2): pass@allure.step("验证登录过程")def test_login(): open() input_UsernameAndPassWord() {arg1}和{arg2},可以在报告中显示动态内容。Allure支持通过@allure.attach添加附件,丰富测试报告内容。
body:要显示的内容name:附件名称attachment_type:附件类型(需从allure.attachment_type中选择)extension:附件扩展名(可选)import allure@allure.step("验证登录过程")def test_login(): open() input_UsernameAndPassWord()# 添加附件def test_attachments(): allure.attach('HTML页面,HelloWorld!', 'Attach with HTML type', allure.attachment_type.HTML) allure.attach.file('./report.html', attachment_type=allure.attachment_type.HTML) allure.attach.file('./demo.jpg', attachment_type=allure.attachment_type.JPG) allure.attachment_type 提供了多种附件类型,如HTML、JPG等。allure.attach.file 可以直接传入文件路径,支持多种格式。通过合理使用@allure.step和@allure.attach,可以显著提升测试报告的可读性和信息量。
转载地址:http://naayz.baihongyu.com/