千纸鹤

  博客园  ::  :: 新随笔  ::  ::  :: 管理
  5 随笔 :: 70 文章 :: 0 评论 :: 9301 阅读
《一》Allure-pytest 配置与入门
(1)Allure测试报告
1.安装JDK1.8 才可运行allure ,怎么安装,直接百度,一大堆
2.下载 https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
3.解压Allure压缩包(D:\安装包,解压到D:)
4.配置Allure到环境变量,到path里面,D:\allure-commandline\allure-2.13.2\bin
5.验证:allure --version
6.要集成pytest实现allure的展示,需要安装pip install allure-pytest 验证:pip show allure-pytest
(2)简单的功能:Allure入门小程序_DEMO
<-----conftest.py----->
#coding=utf-8
import pytest

@pytest.fixture()
def login():
print("用例准备工作")
<-----test_allure.py----->
#coding=utf-8
import os
import allure
import pytest
@allure.step("步骤1:登陆")
def step_1():
print("点击登陆")

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

class TestEditPage():
def test_1(self,login):
step_1()
step_2()
print("执行登陆")

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

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

《二》自动化用例与功能用例关联
(1)功能用例
自动化用例是去翻译你的功能用例,一个一个去覆盖,让功能用例编程自动化的用例,一一 对应起来的
(2)自动化用例
feature 特性名称
story 用户故事/场景
title 对应用例的标题
testcase 对应禅道系统的bug用例url地址,关联起来
issue 如果这个用例有bug,应该关联对应的bug地址
step 用例步骤描述
功能用例整体描述:写在用例方法的注释里
(3)自动化用例与功能用例关联_DEMO
<-----test_case_01.py----->
#coding=utf-8
import os
import allure
import pytest

@allure.feature("编辑分类文章")
class TestArticaleClassify():
@allure.story("典型场景")
@allure.title("编辑文章分类,重复保存,保存失败")
@allure.issue("http://127.0.0.1:8080/zentao/bug-view-1.html") # 禅道bug地址
@allure.testcase("http://127.0.0.1:8080/zentao/testcase-view-5-1.html") # 禅道用例链接地址
def test_edit_classify(self):
"""
编辑文章分类,重复保存,保存失败
前置条件:1.登录
步骤:
1.编辑文章分类,输入文章类别,如计算机
2.点击保存按钮
3.重新打开编辑页面,输入:计算机
4.再次点击保存按钮
预期结果:
1.输入成功
2.保存成功
3.输入成功
4.保存失败,提示:已存在
"""
with allure.step("step:登陆"):
print("登陆")
assert 1 == 1
with allure.step("step1:编辑文章分类,输入文章类别,如计算机"):
print("step1")
assert 1 == 1
with allure.step("step2:点击保存按钮"):
print("step2")
assert 1 == 1
with allure.step("step3:重新打开编辑页面,输入:计算机"):
print("step3")
assert 3 == 4
with allure.step("step4:再次点击保存按钮"):
print("step4")
assert 4 == 5

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

《三》用例等级设置
(1)allure对用例的等级划分成五个等级
blocker 阻塞缺陷(功能未实现,无法下一步)
critical 严重缺陷(功能点缺失)
normal 一般缺陷(边界情况,格式错误)
minor 次要缺陷(界面错误与ui需求不符)
trivial 轻微缺陷(必须项无提示,或者提示不规范)
(2)用例等级设置_DEMO
<-----test_case.py----->
@allure.severity("normal")
def test_case_1():
"""
修改个人姓名-置空
"""
print("用例1111")

@allure.severity("critical")
def test_case_2():
"""
修改个人信息-设置为系统已有人员的信息
"""
print("用例2222")

@allure.severity("critical")
def test_case_3():
"""
修改个人姓名-生日必选项置空保存
"""
print("用例3333")

@allure.severity("blocker")
def test_case_4():
"""
修改个人姓名-点击保存成功
"""
print("用例4444")

def test_case_5():
"""
不设置等级,默认等级为
"""
print("用例5555")

if __name__ == '__main__':
# 执行所有的用例级别
# pytest.main(['--alluredir','./muzi'])
# os.system('allure generate ./muzi/ -o ./report/ --clean')

# 如果有很多测试用例,现在想做快速回顾,只执行用例级别为blocker和critical的测试用例
# 第一种方式:
# pytest.main(['--alluredir','./muzi','--allure-severities','blocker,critical','--clean-alluredir'])
# os.system('allure generate ./muzi/ -o ./report/ --clean')

# 第二种方式:
pytest.main(['--alluredir', './muzi', '--allure-severities', 'blocker,critical'])
os.system('allure serve muzi')

《四》Allure用例描述详解
<-----test_case.py----->
#coding=utf-8
import os
import allure
import pytest

"""
假设这是一个登陆操作,简单实现为一个print
"""

@pytest.fixture
def login_fix():
print("前置条件:登陆")

"""
封装常用的方法
"""
@allure.step("某某常用操作一")
def step_1():
print("常用操作一-----------------")

@allure.step("某某常用操作二")
def step_2():
print("常用操作二-----------------")

@allure.step("某某常用操作三")
def step_3():
print("常用操作三-----------------")

@allure.epic("大模块名称:NGBSS")
@allure.feature("文章编辑")
class TestDemoAllure():
@allure.testcase("http://127.0.0.1:8666/zentao/testcase-view-6-1.html")
@allure.issue("http://127.0.0.1:8666/zentao/bug-view-1.html")
@allure.title("用例标题一")
@allure.story("测试场景一")
@allure.severity("critical")
def test_case_1(self,login_fix):
"""
用例标题
步骤
预期结果
"""
step_1()
step_2()

@allure.story("测试场景二")
def test_case_2(self,login_fix):
step_1()
step_3()

@allure.epic("大模块名称:CBS")
@allure.feature("欠费催缴")
class TestDemoAllure2():

@allure.story("测试场景三")
@allure.severity("critical")
def test_case_3(self,login_fix):
"""
用例标题
步骤
预期结果
"""
step_1()

@allure.story("测试场景四")
def test_case_4(self,login_fix):
step_3()

if __name__ == '__main__':
# pytest.main(['--alluredir','./muzi'])
# os.system('allure serve muzi')

# 根据epic执行
# pytest.main(['--alluredir','./muzi',
# '--allure-epics=大模块名称:NGBSS',
# '--clean-alluredir'])
# os.system('allure serve muzi')

# 根据feature来执行
# pytest.main(['--alluredir','./muzi',
# '--allure-features=欠费催缴',
# '--clean-alluredir'])
# os.system('allure serve muzi')

# 根据story来执行
# pytest.main(['--alluredir', './muzi',
# '--allure-stories=测试场景四',
# '--clean-alluredir'])
# os.system('allure serve muzi')

# 多条件筛选
pytest.main(['--alluredir', './muzi',
'--allure-stories=测试场景四,测试场景三',
'--clean-alluredir'])
os.system('allure serve muzi')
posted on   隆江猪脚饭  阅读(187)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示