当前位置:网站首页>Allure环境部署与生成+Allure内容增强
Allure环境部署与生成+Allure内容增强
2022-07-29 23:05:00 【司小幽】
1.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')
边栏推荐
猜你喜欢
随机推荐
The first round of the real offer harvester~ How does the big factory inspect the candidates?(with detailed answer)
【leetcode】剑指 Offer II 002. 二进制加法
超分之RVRT
JetsonNano learning (5) JetsonNano installs PyTorch and Torchvision
pnpm + workspace + changesets 构建你的 monorepo 工程
BGP联邦综合实验
【C语言入门】ZZULIOJ 1036-1040
This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
We launched a "developer lab"
[leetcode] 75. Color classification (medium) (double pointer, in-situ modification)
地狱挖掘者系列#1
Cloud computing 1+X openstack articles
How to make labview an application (labview program recognizes shapes)
流水线上的农民:我在工厂种蔬菜
MySQL面试题:用户金额充值面试题详解
【LeetCode-SQL每日一练】——2. 第二高的薪水
C语言初阶-初识C语言
jenkins使用维护
Huawei 14 Days - (3) Kernel Development
设计消息队列存储消息的MySQL表格






![Win7x64中使用PowerDesigner连接Oralce数据库报“[Oracle][ODBC][Ora]ORA-12154:TNS:无法解析指定的连接标识符”错误解决方法](/img/47/9d17f3026b862927af8917f3a8fcad.png)


