2-Allure的使用

Allure简介

 allure是一款开源的测试报告的框架,支持多种语言、测试框架。allure会将测试用例的执行数据保存到xml文件当中,再利用allure的命令行将文件转换成html形式呈现出来。

Allure环境搭建

  1. 官网下载allure zip包:https://github.com/allure-framework/allure2/releases
  2. 将包解压到任何一个目录,解压后将bin路径设置到环境变量path中
  3. 命令窗口输入 pip install allure-pytest
  4. 安装完成后,命令窗口输入allure,验证是否安装成功

Allure使用示例

import pytest
import os
import allure

class TestLogin:
    def test_login01(self):
        assert 1 + 1 == 2

if __name__ == '__main__':
    # 步骤1、--alluerdir 存放目录
    pytest.main(['test_func01.py','-s','--alluredir','../report/tmp']) 
    
    # 步骤2、allure generate allure报告  cmd命令
    # 将../report/tmp中的文件 生成报告放到 ../report/report
    os.system('allure generate ../report/tmp -o ../report/report --clean')

执行结果:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
浏览器打开报告,界面如下:
在这里插入图片描述

Allure层级的设置

import pytest
import os
import allure

@allure.epic('项目名称')
@allure.feature('模块名称')  
class TestLogin:
    @allure.story('用户故事')  
    @allure.title('用例标题') 
    def test_login01(self):
        assert 1 + 1 == 2

if __name__ == '__main__':
    pytest.main(['test_func01.py','-s','--alluredir','../report/tmp'])
    os.system('serve ../report/tmp')

在这里插入图片描述

注:层级名称可进行参数化

标签名称使用变量

@allure.title("{变量名}")

报告中加链接

@allure.link(‘链接’)

报告中加附件

需要在方法中加:allure.attach.file(r’…/data/1.jpg’, ‘图片名’, attachment_type=allure.attachment_type.JPG)

报告中加enviroment

在allure生成的xml文件夹中,创建enviroment.properties文件
文件中写入

Browser = Firefox  #浏览器
Browser.version = 77  #浏览器版本
Stand = {
    
    你的项目名}
ApiUrl = {
    
    你的url}
python.Version = 3.9  #python版本

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45128456/article/details/112543778