1987WEB视界-分享互联网热点话题和事件

您现在的位置是:首页 > WEB开发 > 正文

WEB开发

Allure定制报告

1987web2024-03-26WEB开发47
目录1、定制报告常用的装饰器2、allure.dynamic在测试方法中动态添加定制3、用例等级的定制4、用例描述的定制5、链接的定制6、步骤的定

目录
1、定制报告常用的装饰器2、allure.dynamic在测试方法中动态添加定制3、用例等级的定制4、用例描述的定制5、链接的定制6、步骤的定制7、附件的定制

1、定制报告常用的装饰器

结合表和示例图查看

使用方法参数值参数说明@allure.epic()项目名称项目名称,树结构第一层@allure.feature()模块名称模块名称,树结构第二层@allure.story()用户故事测试用例分组名,树结构第三层@allure.title()用例标题测试用例标题,树结构第四层@allure.severity()用例等级/优先级blocker,critical,normal,minor,trival@allure.description()用例描述用例描述@allure.link()自定义链接@allure.issure()bug链接地址@allure.testcase()测试用例地址@allure.step()测试步骤@allure.attachment()附件

示例图

2、allure.dynamic在测试方法中动态添加定制

在对测试方法进行参数化的时候,使用@allure.title装饰器只能对所有测试用例定制一样的标题,想要动态定制用例标题可以在测试方法中使用allure.dynamic.title()来进行定制。定制代码示例

login_data=[("登录成功用例","zhangsan","password","success"),("密码错误用例","zhangsan","passwd","failed_password"),("用户不存在","lisi","password","user_not_exists")]@pytest.mark.parametrize("case_title,username,password,expect_result",login_data)deftest_login(case_title,username,password,expect_result):print("登录测试")allure.dynamic.title(case_title)allure.dynamic.description(f"测试用例描述:此条用例期待结果:{expect_result}")

定制效果

实际上表中除了epic所有定制都可以在测试方法中动态定制,具体如下图

3、用例等级的定制

blocker:阻塞缺陷,致命bugcritical:严重缺陷,功能未实现或错误normal:一般缺陷(80%都是此类缺陷),默认等级minor:次要缺陷,界面显示问题trivial:轻微缺陷,提示问题

使用方法:@allure.severity(allure.severity_level.BLOCKER)

注意:该装饰器既可以修饰方法也可以修饰类不修饰的情况下,默认等级为normal

4、用例描述的定制

使用装饰器@allure.description()动态定制allure.dynamic.description()@allure.title("注销用例标题1")@allure.description("测试注销1")deftest_logout(self):print("注销")allure.dynamic.title("注销用例标题2")allure.dynamic.description("测试注销2")

注意:使用动态定制会覆盖使用装饰器定制

5、链接的定制

测试用例链接:@allure.testcase(url=链接地址,name=名称)bug链接:@allure.issue(url=链接地址,name=名称)自定义链接:@allure.link(url=链接地址,name=名称)@allure.link(url="https://passport.jd.com/new/login.aspx",name="登录地址")@allure.issue(url="https://www.google.com",name="bug列表地址1")@allure.testcase(url="https://testlink.org/",name="测试用例地址1")@pytest.mark.parametrize("case_title,username,password,expect_result",login_data)deftest_login(self,case_title,username,password,expect_result):print("登录测试")allure.dynamic.link(url="https://www.baidu.com",name="登录链接")allure.dynamic.issue(url="https://www.baidu.com",name="bug列表地址2")allure.dynamic.testcase(url="https://www.baidu.com",name="测试用例地址2")

注意:链接同样支持动态定制动态定制不会覆盖装饰器定制,会把所有链接都显示出来

6、步骤的定制

使用装饰器@allure.step()在测试方法内使用with allure.step():

示例:

@allure.epic("电商项目")@allure.feature("购物车模块")classTestCart:@allure.step("第一步,测试加入购物车")@allure.story("测试添加购物车方法")@allure.title("加入购物车测试用例")deftest_add_cart(self):# 第一步,登录withallure.step("第一步,登录"):print("登录成功")# 第二步,搜索商品withallure.step("第二步,搜索商品"):print("搜索成功")# 第三步,将商品加入购物车withallure.step("第三步,加入购物车"):print("加入购物车成功")# 第四步,打开购物车withallure.step("第四步,打开购物车"):print("打开购物车成功")# 第五步,断言验证是否添加成功withallure.step("第五步,断言验证是否加入成功"):print("验证加入购物车通过")

7、附件的定制

使用allure.attachment对附件进行定制参数:

body:附件内容name:附件名称attachment_type:附件类型,支持的类型如下

UI自动化项目

deftest_register(self):print("注册测试")withopen("./allure_demo/screen_shot/fail_snap.jpg","rb")asf:allure.attach(body=f.read(),name="注册测试失败截图",attachment_type=allure.attachment_type.JPG)

接口自动化项目

deftest_search_api():allure.attach(body=url,name="请求地址",attachment_type=allure.attachment_type.TEXT)allure.attach(body=json.dumps(params),name="请求参数",attachment_type=allure.attachment_type.TEXT)resp=requests.get(url,params=params)allure.attach(body=resp.text,name="响应数据",attachment_type=allure.attachment_type.TEXT)

声明:本站所有文章,如无特殊说明或标注,均为爬虫抓取以及网友投稿,版权归原作者所有。