allure step 编写测试用例的两种方式
1.方式一:测试用例中with allure.step():
# common_fucntion.py
import allure
import pytest
'''
流程性的用例,添加测试步骤,让用例更清晰
用例步骤:1.登陆, 2.浏览商品 3.添加购物车4.生成订单5.支付成功
'''
def login(username, password):
'''登陆'''
print("前置操作:先登陆")
def open_goods():
'''浏览商品'''
print("浏览商品")
def add_shopping_cart(goods_id="10086"):
'''添加购物车'''
print("添加购物车")
def buy_goods():
'''生成订单'''
print("buy")
def pay_goods():
'''支付'''
print("pay") test_allure_step.py
# test_allure_step.py
import allure
import pytest
from .common_function import *
'''
流程性的用例,添加测试步骤,让用例更清晰
用例步骤:1.登陆, 2.浏览商品 3.添加购物车4.生成订单5.支付成功
'''
@pytest.fixture(scope="session")
def login_setup():
login("yoyo", "123456")
@allure.feature("功能模块")
@allure.story("测试用例小模块-成功案例")
@allure.title("测试用例名称:流程性的用例,添加测试步骤")
def test_add_goods_and_buy(login_setup):
'''
用例描述:
前置:登陆
用例步骤:1.浏览商品 2.添加购物车3.购买4.支付成功
'''
with allure.step("step1:浏览商品"):
open_goods()
with allure.step("step2:添加购物车"):
add_shopping_cart()
with allure.step("step3:生成订单"):
buy_goods()
with allure.step("step4:支付"):
pay_goods()
with allure.step("断言"):
assert 1 == 1
测试报告:
2.方式二:
直接使用allure.step() 装饰器定义在步骤的函数上面
import allure
import pytest
'''
流程性的用例,添加测试步骤,让用例更清晰
用例步骤:1.登陆, 2.浏览商品 3.添加购物车4.生成订单5.支付成功
'''
@allure.step("setup:登陆")
def login(username, password):
'''登陆'''
print("前置操作:先登陆")
@allure.step("step:浏览商品")
def open_goods():
'''浏览商品'''
print("浏览商品")
@allure.step("step:添加购物车")
def add_shopping_cart(goods_id="10086"):
'''添加购物车'''
print("添加购物车")
@allure.step("step:生成订单")
def buy_goods():
'''生成订单'''
print("buy")
@allure.step("step:支付")
def pay_goods():
'''支付'''
print("pay")
用例
请 import allure import pytest
from .common_function import *
# 作者:上海-悠悠 QQ交流群:779429633
@pytest.fixture(scope="session")
def login_setup():
login("yoyo", "123456")
@allure.feature("功能模块")
@allure.story("测试用例小模块-成功案例")
@allure.title("第二种实现方式:流程性的用例,添加测试步骤")
def test_add_goods_and_buy_2(login_setup):
'''
用例描述:
前置:登陆
用例步骤:1.浏览商品 2.添加购物车3.购买4.支付成功
'''
open_goods()
add_shopping_cart(goods_id="10086")
buy_goods()
pay_goods()
assert 1 == 1
报告:
3.两种方式比较
使用 with allure.step("step:步骤") 这种方式代码可读性更好一点,但不会带上函数里面的传参和对应的值。
使用 @allure.step("step:步骤") 这种方式会带上函数的传参和对应的值。
这两种方式结合起来使用,才能更好的展示测试报告!
结合使用案例:
with allure step():可以集成一些截图,通过attach来格式化输出报告:
页:
[1]