自动化测试之Allure测试报告

  1、使用步骤

  1. 安装

pip install allure-pytest

  2. 将 pytest 配置文件中的命令行参数加上如下代码

--alluredir report

  编写好测试脚本后,正常的在命令行中运行 pytest 即可,程序运行结束后,会在项目的report目录中生成一些json文件。

 

  3. 将测试结果json文件转成 html

  1)https://bintray.com/qameta/generic/allure2 下载 allure-2.6.0.zip

  2)解压缩到一个目录(不经常动的目录)

  3)将压缩包内的 bin 目录配置到 path 系统环境变量

  4)右键我的电脑 - 属性 - 高级设置 - 环境变量 - 找到系统环境变量的path项 - 增加 allure到bin 目录

  5)在命令行中敲 allure 命令,如果提示有这个命令,即为成功

  6)进入 report 上级目录执行命令

allure generate report/ -o report/html --clean

  report/ 表示测试结果文件所在的目录

  -o 表示 output 输出

  report/html 表示将 index.html 报告生成到哪个文件夹

 

2、Allure 与 pytest 结合

1. 添加测试步骤

在操作层中的方法上加上装饰器
@allure.step(title="测试步骤001")

示例:

class LoginHandle(BaseHandle):
    def __init__(self):
        self.login_page = LoginPage()

    @allure.step(title="输入手机号")
    def input_mobile(self, mobile):
        self.input_text(self.login_page.find_mobile(), mobile)

    @allure.step(title="输入验证码")
    def input_code(self, code):
        self.input_text(self.login_page.find_code(), code)

2. 添加图片描述

在需要截图的地方添加如下代码:
allure.attach(driver.get_screenshot_as_png(), "截图", allure.attachment_type.PNG)

3. 添加严重级别

在测试脚本中,增加装饰器
@allure.severity(allure.severity_level.BLOCKER)

参数有五个,对应不同的优先级:

1. BLOCKER 最严重

2. CRITICAL 严重

3. NORMAL 普通

4. MINOR 不严重

5. TRIVIAL 最不严重

4. 在项目中生成测试报告

 使用步骤:

1. 将 pytest 配置文件中的命令行参数加上 --alluredir=report

2. 执行测试用例

3. 生成HTML测试报告, allure generate report/ -o report-html/ --clean

posted @ 2022-07-05 16:59  MToy  阅读(416)  评论(0)    收藏  举报