allure定制报告
Feature: 功能块,feature功能分块时比story大,即同时存在feature和story时,feature为父节点
Story: 功能块,具有相同feature或story的用例将规整到相同模块下,执行时可用于筛选
Severity: 标注测试用例的重要级别,包含blocker, critical, normal, minor, trivial 几个不同的等级
Step: 标注测试用例步骤
Issue:问题标识,关联标识已有BUG的问题,可为一个url链接地址
TestCase: # 用例标识,关联标识用例,可为一个url链接地址
attach: 标注一些附加内容到测试报告中
Environment: 标注环境Environment字段
1、Features定制详解
Feature: 功能块,feature功能分块时比story大,即同时存在feature和story时,feature为父节点
复制代码
# coding=utf-8
import os
import allure
fileName = os.path.split(os.path.realpath(__file__))[1]
@allure.feature(f"{fileName}文件feature标注的第一个用例")
def test_case1():
a = 1
b = 1
c = a + b
assert c == 2
@allure.feature(f"{fileName}文件feature标注的第二个用例")
def test_case2():
a = "aaaaaaaaa"
assert len(a) == 10
复制代码
2、Story定制详解
Story: 功能块,具有相同feature或story的用例将规整到相同模块下,执行时可用于筛选
复制代码
import os
import allure
fileName = os.path.split(os.path.realpath(__file__))[1]
@allure.feature(f"{fileName}文件feature标注的用例")
@allure.story(f"{fileName}文件story标注的第一个用例")
def test_case1():
a = 1
b = 1
c = a + b
assert c == 2
@allure.feature(f"{fileName}文件feature标注的用例")
@allure.story(f"{fileName}文件story标注的第二个用例")
def test_case2():
a = "aaaaaaaaa"
assert len(a) == 10
复制代码
3、用例标题和用例描述定制详解
def的方法名称为用例名称,3引号注释为用例描述
复制代码
# coding=utf-8
import os
import allure
fileName = os.path.split(os.path.realpath(__file__))[1]
@allure.feature(f"{fileName}")
def test_caseName1():
# test_caseName1为用例title
"""
用例描述:这是test_caseName1的用例描述
"""
# 3引号注释为用例描述
a = 1
b = 1
c = a + b
assert c == 2
@allure.feature(f"{fileName}")
def test_caseName2():
a = "aaaaaaaaa"
assert len(a) == 10
复制代码
4 、Severity定制详解
Severity: 标注测试用例的重要级别,包含blocker, critical, normal, minor, trivial 几个不同的等级
Allure中对严重级别的定义:
1、 Blocker级别:中断缺陷(客户端程序无响应,无法执行下一步操作)
2、 Critical级别:临界缺陷( 功能点缺失)
3、 Normal级别:普通缺陷(数值计算错误)
4、 Minor级别:次要缺陷(界面错误与UI需求不符)
5、 Trivial级别:轻微缺陷(必输项无提示,或者提示不规范)
复制代码
# coding=utf-8
import os
import allure
fileName = os.path.split(os.path.realpath(__file__))[1]
@allure.feature(f"{fileName}")
@allure.story("正向用力")
@allure.severity('blocker')
def test_case1():
a = "aaaaaaaaa"
assert len(a) == 10
@allure.feature(f"{fileName}")
@allure.story("正向用力")
@allure.severity('critical')
def test_case2():
a = "aaaaaaaaa"
assert len(a) == 9
@allure.feature(f"{fileName}")
@allure.story("反向用力")
@allure.severity('normal')
def test_case3():
a = "aaaaaaaaa"
assert len(a) == 10
@allure.feature(f"{fileName}")
@allure.story("反向用力")
@allure.severity('minor')
def test_case4():
a = "aaaaaaaaa"
assert len(a) == 9
@allure.feature(f"{fileName}")
@allure.story("反向用力")
@allure.severity('trivial')
def test_case5():
a = "aaaaaaaaa"
assert len(a) == 9
复制代码
5、Step定制详解
标注测试用例步骤
复制代码
# coding=utf-8
import os
import allure
fileName = os.path.split(os.path.realpath(__file__))[1]
@allure.feature(f"{fileName}")
@allure.story("正向用力")
@allure.step('用例步骤')
def test_case1():
"""
用例描述:计算两步相加之和
"""
with allure.step('step1:返回a的值'):
a = 1
with allure.step('step2:返回b的值'):
b = 2
with allure.step('step3:预期a+b=3'):
assert a + b == 4
复制代码
6、Issue和TestCase定制详解
Issue:问题标识,关联标识已有BUG的问题,可为一个url链接地址
TestCase: # 用例标识,关联标识用例,可为一个url链接地址
复制代码
# coding=utf-8
import os
import allure
fileName = os.path.split(os.path.realpath(__file__))[1]
@allure.feature(f"{fileName}")
@allure.story("正向用力")
@allure.step('用例步骤')
@allure.issue("http://www.baidu.com")
@allure.testcase("http://www.testlink.com")
def test_case1():
"""
用例描述:计算两步相加之和
"""
with allure.step('step1:返回a的值'):
a = 1
with allure.step('step2:返回b的值'):
b = 2
with allure.step('step3:预期a+b=3'):
assert a + b == 4
复制代码
7、Environment定制详解
Environment: 标注环境配置Environment字段
复制代码
# coding=utf-8
import allure
allure.environment(app_package='com.mobile.fm')
allure.environment(test="hhhhhh")
allure.environment(域名="127.0.0.1")
复制代码
8、attach定制详解
在报告中增加附件:allure.attach(’arg1’,’arg2’,’arg3’):
arg1:是在报告中显示的附件名称
arg2:表示添加附件的内容
arg3:表示添加的类型(支持:HTML,JPG,PNG,JSON,OTHER,TEXTXML)
复制代码
# coding=utf-8
import os
import allure
fileName = os.path.split(os.path.realpath(__file__))[1]
@allure.feature(f"{fileName}")
@allure.story("正向用力")
@allure.step('用例步骤')
def test_case1():
"""
用例描述:计算两步相加之和
"""
with allure.step('step1:返回a的值'):
allure.attach('背景1', '没有背景') # attach可以打印一些附加信息
allure.attach('背景2', '没有背景')
a = 1
with allure.step('step2:返回b的值'):
with open(r"C:\Users\Administrator\Desktop\qwe.jpg","rb") as f:
f = f.read()
allure.attach('图片',f,allure.attach_type.JPG)
b = 2
with allure.step('step3:预期a+b=3'):
assert a + b == 4
复制代码