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

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

一、@allure.step的用法

  • 可以理解为我们编写测试用例中的每一步操作步骤,而在allure中表示对每个测试用例进行非常详细的步骤说明
  • 通过 @allure.step(),可以让测试用例在allure报告中显示更详细的测试过程

示例代码:

# -*- 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的显示

小结

  • step(参数),参数就是标题,你传什么,在allure上的步骤名就显示什么
  • 支持位置参数和关键字参数 {arg1},{arg2},可参考报告中“ 输入账号、密码'xiaoqiang','1',并点击登录”处,如果函数的参数没有匹配成功就会报错

二、allure.attach的用法

作用: 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报告中展示如下:

你可能感兴趣的文章
Nmap扫描教程之Nmap基础知识
查看>>
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
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
查看>>