当前位置:网站首页>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')
边栏推荐
猜你喜欢

新型LaaS协议Elephant Swap给ePLATO提供可持续溢价空间

高数下|三重积分习题课|高数叔|手写笔记

纳米金颗粒修饰核酸产品|碳纳米管载核酸-DNA/RNA材料|解析说明

In 2022, the latest Gansu construction staff (material staff) mock exam questions and answers

嵌入式系统驱动初级【1】——内核模块上_编译方法

Access the company intranet

Topics in Dynamic Programming

【LeetCode-SQL每日一练】——2. 第二高的薪水

html+css+php+mysql实现注册+登录+修改密码(附完整代码)

MySQL数据库进阶篇
随机推荐
【LeetCode-SQL每日一练】——2. 第二高的薪水
【技术规划】描绘未来第 4 部分:技术路线图
Three chess (written in C language)
html+css+php+mysql实现注册+登录+修改密码(附完整代码)
【无标题】
Mysql内外连接
BGP联邦综合实验
【openlayers】地图【一】
暴力递归到动态规划 03 (背包问题)
Another new rule for credit cards is coming!Juphoon uses technology to boost the financial industry to improve service quality and efficiency
PLSQL Developer安装和配置
DNA偶联二维过渡金属硫化物|DNA修饰贵金属纳米颗粒|使用方法
Implementation and implementation of Any to Any real-time voice change丨RTC Dev Meetup
y81.第四章 Prometheus大厂监控体系及实战 -- 监控扩展(十二)
【leetcode】75. 颜色分类(中等)(双指针、原地修改)
Foxmail是什么邮箱?
In 2022, the latest Gansu construction staff (material staff) mock exam questions and answers
【leetcode】剑指 Offer II 006. 排序数组中两个数字之和(二分查找、双指针)
【2023校招刷题】笔试及面试中常考知识点、手撕代码总结
地狱挖掘者系列#1