本文共 1966 字,大约阅读时间需要 6 分钟。
示例代码:
# -*- coding: utf-8 -*-# @Time : 2020/12/12 8:34# @Author : longrong.lang# @FileName: test_allure.py# @Software: PyCharm# @Cnblogs :https://www.cnblogs.com/longronglangimport 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()
测试用例在allure的显示
作用: allure报告还支持显示许多不同类型的附件,可以补充测试结果;可根据自身情况进行调整
语法: allure.attach(body, name, attachment_type, extension)body:要显示的内容(附件)
name:附件名字attachment_type:附件类型,是 allure.attachment_type 里面的其中一种extension:附件的扩展名(比较少用)allure.attachment_type提供了哪些附件类型?
语法二: allure.attach.file(source, name, attachment_type, extension)
source:文件路径,相当于传一个文件示例代码如下:# -*- coding: utf-8 -*-# @Time : 2020/12/12 8:34# @Author : longrong.lang# @FileName: test_allure.py# @Software: PyCharm# @Cnblogs :https://www.cnblogs.com/longronglangimport 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()# 添加附件def test_attachments(): # 在测试报告中画了一个html页面 allure.attach('HTML页面,HelloWorld! ', 'Attach with HTML type', allure.attachment_type.HTML) # 添加一个html附件 allure.attach.file('./report.html', attachment_type=allure.attachment_type.HTML) # 添加一个图片附件 allure.attach.file('./demo.jpg', attachment_type=allure.attachment_type.JPG)
在allure报告中展示如下: