Allure环境部署与生成+Allure内容增强

38 篇文章 6 订阅
23 篇文章 0 订阅
本文档详细介绍了Allure报告的配置方法,包括解决执行时的乱码问题,以及如何将自动化测试用例与功能关联。通过示例展示了如何设置用例等级,并深入解析了Allure用例描述的编写,包括用例的史诗、特性、故事、标题、问题链接和测试用例链接。此外,还演示了如何在测试中添加用例步骤描述,以及如何根据用例等级筛选执行测试。
摘要由CSDN通过智能技术生成


1.Allure配置与入门

执行测试用例时,allure展示乱码的解决办法

2.自动化用例与功能关联

1.功能用例

conftest.py
import pytest


@pytest.fixture(autouse = True)
def fix():
    print("用例准备工作")

2.自动化用例

# 这不是用例函数,只是普通函数

import os

import allure
import pytest

@allure.step("步骤1:登录")
def step_1():
    print("点击登录")

@allure.step("步骤2:输入用户名密码")
def step_2():
    print("输入用户名密码")


@allure.feature("编辑分类文章")
# 测试类和测试用例
class TestEditPage():
    # 测试用例

    @allure.story("文章编辑")
    @allure.title("编辑文章分类,重复保存,保存失败")
    @allure.issue("http://127.0.0.1:8080/zentao/buge-login.html") #禅道系统的地址
    @allure.testcase("http://127.0.0.1:8080/zentao/testcase-login.html") #禅道测试用例的地址
    def test_1(self):
        """
            编辑文章分类,重复保存,保存失败
            前置条件: 1.登录
            步骤:
                1.编辑文章分类,输入文章类别,如计算机
                2 点击保存按钮
                3.重新打开编辑页面,输入:计算机
                4.再次点击保存按钮
            预期结果:
                1.输入成功
                2.保存成功
                3.输入成功
                4.保存失败,提示:已存在
        :return:
        """


        step_1()
        step_2()
        print("执行登录")

    def test_2(self):
        print("查询商品")


if __name__ == '__main__':
    # pytest.main(['-vs'])
    pytest.main(['--alluredir','./result'])
    # 执行命令行的命令
    # os.system('allure generate ./life -o ./report')
    # 这个clean没有清理任何内容,只是允许你重复使用同一个目录生成报告,数据都会保留
    os.system('allure generate ./result -o ./report --clean')

3.用例等级设置


"""
用例等级
allure对用例的等级划分成五个等级:
blocker 阻塞缺陷(功能未实现,无法下一步)
critical 严重缺陷(功能点缺失)
normal 一般缺陷(边界情况,格式错误)默认等级
minor 次要缺陷(界面错误与ui需求不符)
trivial 轻微缺陷(必须项无提示,或者提示不规范)
"""
import os

import allure
import pytest


@allure.severity('normal')
def test_case01():
    print("测试用例一")

@allure.severity('critical')
def test_case02():
    print("测试用例二")

@allure.severity('blocker')
def test_case03():
    print("测试用例三")


def test_case04():
    print("测试用例四")


def test_case05():
    print("测试用例五")


def test_case06():
    print("测试用例六")


def test_case01():
    print("测试用例一")

if __name__ == '__main__':
    # pytest.main(['--alluredir','./result'])
    # 如果有很多用例,现在想快速的回顾,只执行用例等级为blocker和critical的用例
    pytest.main(['--alluredir','./result','--allure-severities','blocker,critical','--clean-alluredir'])
    os.system('allure serve result')

4.Allure用例描述详解

conftest.py
import pytest


@pytest.fixture(autouse = True)
def fix():
    print("用例准备工作")

# 这不是用例函数,只是普通函数

import os

import allure
import pytest

@allure.step("步骤1:登录")
def step_1():
    print("点击登录")

@allure.step("步骤2:输入用户名密码")
def step_2():
    print("输入用户名密码")

@allure.epic("CRM后台系统: UI自动化")
@allure.feature("编辑分类文章")
# 测试类和测试用例
class TestEditPage():
    # 测试用例

    @allure.story("文章编辑")
    @allure.title("编辑文章分类,重复保存,保存失败")
    @allure.issue("http://127.0.0.1:8080/zentao/buge-login.html") #禅道系统的地址
    @allure.testcase("http://127.0.0.1:8080/zentao/testcase-login.html") #禅道测试用例的地址
    @allure.severity("critical")
    def test_1(self):
        """
            编辑文章分类,重复保存,保存失败
            前置条件: 1.登录
            步骤:
                1.编辑文章分类,输入文章类别,如计算机
                2 点击保存按钮
                3.重新打开编辑页面,输入:计算机
                4.再次点击保存按钮
            预期结果:
                1.输入成功
                2.保存成功
                3.输入成功
                4.保存失败,提示:已存在
        :return:
        """


        step_1()
        step_2()
        print("执行登录")

    @allure.story("商品查询")
    @allure.title("查询可用的商品")
    def test_2(self):
        print("查询商品")


@allure.epic("CRM后台系统: UI自动化")
@allure.feature("人员管理")
class TestCase02:
    @allure.story("测试场景二")
    def test_case_3(self):
        """
            用例标题
            步骤
            预期结果
        :return:
        """
        step_1()


if __name__ == '__main__':
    # pytest.main(['-vs'])
    pytest.main(['--alluredir','./result'])
    # 执行命令行的命令
    # os.system('allure generate ./life -o ./report')
    # 这个clean没有清理任何内容,只是允许你重复使用同一个目录生成报告,数据都会保留
    os.system('allure generate ./result -o ./report --clean')

5.Allure添加用例步骤描述详解

import os

import allure
import pytest

from class34.pytest_allure_step.case02.common_function_07 import *


@pytest.fixture()
def login_fix():
    with allure.step("setup:登录"):
        login("zz","123456")

@allure.feature("购物模块")
@allure.title("测试购物流程")
def test_shopping(login_fix):
    """
        用例步骤:
            `1.登录
             2.浏览商品
             3.添加购物车
             4.生成订单
             5.支付成功
    :param login_fix:
    :return:
    """
    with allure.step("浏览商品"):
        open_goods()
        with allure.step("嵌套步骤"):
            add_cart()
    with allure.step("添加购物车"):
        add_cart()
        assert 1 == 2
    with allure.step("购买商品"):
        buy_goods()
    with allure.step("支付"):
        pay_goods()

if __name__ == '__main__':
    pytest.main(['--alluredir', './result'])
    os.system('allure generate ./result -o ./report --clean')

import allure


@allure.step("登录")
def login(username,password):
    """登录"""
    print("前置操作:先登录")

@allure.step("浏览商品")
def open_goods():
    """浏览商品"""
    with allure.step("步骤1:选择颜色"):
        pass
    with allure.step("步骤2:选择大小"):
        pass

    print("浏览商品")

@allure.step("添加商品到购物车")
def add_cart(goods_id="10086"):
    """添加购物车"""
    print("添加购物车")

@allure.step("生成订单")
def buy_goods():
    """生成订单"""
    print("buy")

@allure.step("支付")
def pay_goods():
    """支付"""
    print("支付")

import os

import allure
import pytest

from class34.pytest_allure_step.case02.common_function_07 import *


@pytest.fixture()
def login_fix():
    with allure.step("setup:登录"):
        login("zz","123456")

@allure.feature("购物模块")
@allure.title("测试购物流程")
def test_shopping(login_fix):
    """
        用例步骤:
            `1.登录
             2.浏览商品
             3.添加购物车
             4.生成订单
             5.支付成功
    :param login_fix:
    :return:
    """
    open_goods()
    add_cart()
    buy_goods()
    pay_goods()

if __name__ == '__main__':
    pytest.main(['--alluredir', './result'])
    os.system('allure generate ./result -o ./report --clean')

6.Other

conftest.py
import allure
import pytest

# @allure.step 放在@pytest.fixture上面不行,放在下面可以
# @allure.step("登录的前置操作")
# @pytest.fixture
# def fix():
#         print("登录")


# @allure.step直接用在fix上是不生效的
@allure.step("登录的前置操作")
@pytest.fixture
def fix1():
    with allure.step("登录的前置操作"):
        print("登录")


@pytest.fixture
@allure.step("登录的前置操作")
def fix2():
    print("登录")

import os

import pytest


def test_case(fix1,fix2,fix3):
    print("测试用例一")

if __name__ == '__main__':
    pytest.main(['--alluredir', './result'])
    os.system('allure generate ./result -o ./report --clean')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

司小幽

真诚赞赏,手留余香。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值