博客
关于我
Pytest学习(二十)- allure之@allure.step()、allure.attach的详细使用
阅读量:463 次
发布时间:2019-03-06

本文共 1239 字,大约阅读时间需要 4 分钟。

Allure框架使用手册

@allure.step的用法

@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()

测试用例在Allure报告中的显示

  • 每个步骤描述会在报告中以明确的条目呈现。
  • 支持参数替换,例如{arg1}{arg2},可以在报告中显示动态内容。

@allure.attach的用法

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 提供了多种附件类型,如HTMLJPG等。
  • allure.attach.file 可以直接传入文件路径,支持多种格式。

通过合理使用@allure.step@allure.attach,可以显著提升测试报告的可读性和信息量。

转载地址:http://naayz.baihongyu.com/

你可能感兴趣的文章
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
no1
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
查看>>