当前位置:网站首页>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')
边栏推荐
- pnpm + workspace + changesets 构建你的 monorepo 工程
- 通过 FileUploader 的初始化,了解 SAP UI5 应用的 StaticArea 初始化逻辑
- 【面试:并发篇34:Unsafe】
- 【面试:并发篇30:多线程:happen-before】
- 【MySQL系列】 MySQL表的增删改查(进阶)
- This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
- Embedded system driver primary [1] - kernel module _ compilation method
- go语言中的goroutine(协程)
- Qt uses QSortFilterProxyModel for sorting and filtering in QML
- 流水线上的农民:我在工厂种蔬菜
猜你喜欢

BGP联邦综合实验

PyCharm使用教程(详细版 - 图文结合)

真offer收割机 第一弹~大厂如何考察候选人?(附答案详解)
![[leetcode] 82. Delete duplicate elements in sorted linked list II (medium)](/img/93/a744cfc059245de2fc07894167f3c5.png)
[leetcode] 82. Delete duplicate elements in sorted linked list II (medium)

Another new rule for credit cards is coming!Juphoon uses technology to boost the financial industry to improve service quality and efficiency

MySQL面试题:用户金额充值面试题详解

DNA修饰碳纳米管|DNA修饰单层二硫化钼|DNA修饰二硫化钨(注意事项)

MQTT over QUIC:下一代物联网标准协议为消息传输场景注入新动力

Hell Diggers Series #1

Design for failure常见的12种设计思想
随机推荐
SAP ABAP 守护进程的实现方式
资源集合
微信小程序滑动导航栏(网页浮动窗口怎么设置)
@Accessors 注解详解
WeChat applet sliding navigation bar (how to set the floating window of the webpage)
地狱挖掘者系列#1
html+css+php+mysql实现注册+登录+修改密码(附完整代码)
Super RVRT
DNA修饰碳纳米管|DNA修饰单层二硫化钼|DNA修饰二硫化钨(注意事项)
JVM 上数据处理语言的竞争:Kotlin, Scala 和 SPL
The sequence table of the linear table (the dry goods are full of sharing ~ contains all the function codes of the sequence table~
How to realize object selection in canvas (5)
网工知识角|轻松拿offer【网工面试题】三层交换机与路由器有什么区别?
Farmers on the assembly line: I grow vegetables in a factory
MySQL面试题:用户金额充值面试题详解
jenkins use and maintenance
Cloud computing 1+X openstack articles
Hell Diggers Series #1
Redis和MySQL如何保持数据一致性
MQTT over QUIC: The Next-Generation IoT Standard Protocol Brings New Impetus to Messaging Scenarios