从0开始python学习-35.allure报告企业定制

目录

1. 搭建allure环境

2. 生成报告

3. logo定制

4. 企业级报告内容或层级定制

5. allure局域网查看


1. 搭建allure环境

1.1 JDK,使用PyCharm

  1. 找到pycharm安装目录
  2. 找到java.exe
  3. 记下jbr目录的完整路径,eg: C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\jbr\bin
  4. 将地址添加进入环境变量
  5. 重启

1.2 allure程序

  1. 下载地址:https://github.com/allure-framework/allure2/releases
  2. 解压到指定路径。eg: D:\study\allure-2.25.0\allure-2.25.0\bin
  3. 执行allure
  4. Path 追加allure安装路径
  5. 验证是否安装成功:在dos窗口和Pycharm(需要重启加载环境变量)中都需要验证:allure --version

2. 生成报告

2.1 生成临时的json格式的报告

addopts = -vs --alluredir=./temps --clean-alluredir
; --clean-alluredir生成临时报告并清除

2.2 生成HTML的allure报告

if __name__ == "__main__":
    pytest.main(['./test_study/test_fixture.py'])
    os.system("allure generate ./temps -o ./reports --clean") 
    # -o 指定输出测试报告路径
    # --clean 清空历史数据
    # ./temps 表示用来生成html的JSON临时文件目录
    # ./reports 表示html文件生成目录

3. logo定制

3.1 在D:\study\allure-2.25.0\allure-2.25.0\config目录下的allure.yml中配置自定义的logo插件【- custom-logo-plugin】

3.2 重新运行并生成allue报告

3.3 增加一个自己的logo文件并修改D:\study\allure-2.25.0\allure-2.25.0\plugins\custom-logo-plugin\static路径下的styles.css文件里面的样式(最好将需要修改的logo也放在custom-logo-plugin目录下)

.side-nav__brand {
  background: url('1.png') no-repeat left center !important; //将你需要的logo图片地址放在这里
  margin-left: 22px; //调整方位
  height: 90px; //调整大小
  background-size: contain !important;
}
//去掉图片后边 allure 文本
.side-nav__brand-text{
   display: none; 
}
//配置logo 后面的字体样式与字体大小
.side-nav__brand:after {
  content: "测试测试";
  margin-left: 18px;
  height: 20px;
  font-family: Arial;
  font-size: 13px;
}

 注:logo图片和文字可以同时存在,也可以只要一个

4. 企业级报告内容或层级定制

左边:

1. 项目名称(史诗):@allure.epic("测试报告")

2. 模块名称(特性):@allure.feature("测试模块")

3. 接口名称(分组):@allure.story("测试接口")

@allure.epic('测试报告')
@allure.feature('测试模块')
class TestA:
    @allure.story('测试1')
    def test_1(self):
        print('11111')

    @allure.story('测试2')
    def test_2(slef):
        print('22222')

 将多个用例写到一个组:

@allure.story('测试1')
@allure.title('用例1')
def test_1(self):
    print('11111')

@allure.story('测试1')
def test_2(slef):
    allure.dynamic.title('用例2')
    print('22222')

4. 用例标题:@allure.title("用例1") or allure.dynamic.title('用例2') 两种方法都可以实现

@allure.title('用例1') //方法1
def test_1(self):
    print('11111')

@allure.story('测试2')
def test_2(slef):
    allure.dynamic.title('用例2') //方法2
    print('22222')

 右边:

1. 测试用例严重级别:@allure.severity(allure.severity_level.BLOCKER) //BLOCKER(致命),CRITICAL(严重),NORMAL(一般),MINOR(提示),TRIVIAL(轻微),一般默认为NORMAL

@allure.severity(allure.severity_level.TRIVIAL)
@allure.story('测试3')
def test_3(slef):
    print('33333')

 2. 测试用例的描述:@allure.description("测试用例的描述")

@allure.description("测试用例的描述方法1")
@allure.title('测试4')
def test_4(slef):
    print('44444')

@allure.title('测试5')
def test_5(slef):
    allure.dynamic.description("测试用例的描述方法2")
    print('55555')

3. 接口访问链接:@allure.link("接口链接")

4. BUG链接:@allure.issue("bug链接")

5. 测试用例链接:@allure.testcase("用例链接")

@allure.story('测试6')
@allure.link('https://www.baidu.com/0',name='接口链接')
@allure.issue('https://www.baidu.com/',name='bug链接')
@allure.testcase('https://www.baidu.com/',name='用例链接')
def test_6(slef):
    print('66666')

6. 测试用例的操作步骤:allure.step("第"+str(i)+"步"):

@allure.story('测试1')
def test_7(self):
    for i in range(0,10):
        with allure.step("第"+str(i)+"步"):
            pass

7. 测试附件:allure.attach(body=content,name="错误截图",attachment_type=allure.attachment_type.PNG) //一般用于错误截图(常用于web自动化测试)

@allure.story('测试1')
def test_8(self):
    # 附件上传需要使用二进制,可以是图片,可以是文本,可以是其它文件
    with open(r'D:\study\allure-2.25.0\allure-2.25.0\plugins\custom-logo-plugin\static\1.png',mode='rb') as f:
        content = f.read()
        allure.attach(body=content,name='错误截图',attachment_type=allure.attachment_type.PNG)

8. 文本内容的定制:一般应用于接口自动化

@allure.story('测试1')
def test_9(self):
    # 请求
    allure.attach('https://www.baidu.com/0',name='接口地址',attachment_type=allure.attachment_type.TEXT)
    allure.attach('接口参数,一般从yaml中获取',name='接口参数',attachment_type=allure.attachment_type.TEXT)
    allure.attach('请求方式:get/post',name='请求方式',attachment_type=allure.attachment_type.TEXT)
    allure.attach('请求头,一般从yaml中获取',name='请求头',attachment_type=allure.attachment_type.TEXT)

    # 响应
    allure.attach('响应文本,一般从yaml中获取', name='响应文本', attachment_type=allure.attachment_type.TEXT)
    allure.attach('执行结果:成功/失败', name='执行结果', attachment_type=allure.attachment_type.TEXT)

9. 数据驱动:

@allure.story('测试1')
@pytest.mark.parametrize('x', ['这是第1个测试值', "这是第2个测试值"])
def test_a(self,x):
    print(f'test_a中的X值为{x}')

 由于使用数据驱动,用例标题会展示参数数据化驱动中的所有参数,若不想要显示则需要修改allure配置

# 修改前
test_result.parameters.extend(
    [Parameter(name=name, value=represent(value)) for name, value in params.items()
     if name not in current_param_names])
     
# 修改后 (将列表内容去除即可)     
test_result.parameters.extend([])

5. allure局域网查看

局域网(内网):allure open ./reports

if __name__ == "__main__":
    pytest.main(['./test_study/test_allure.py'])
    os.system("allure generate ./temps -o ./reports --clean")
    os.system("allure open ./reports")

  • 17
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值