Allure生成测试报告

慢慢探索&慢慢学习

1.安装allure

allure安装步骤

2.安装 pytest拓展包

pip install alllure-pytest

3.执行测试用例并收集结果

pytest xxx.py(你的case) --alluredir=/temp/my_allure_result

结果:
在这里插入图片描述

4.将结果发送报告

allure serve ./result/tmp

如果发现allure不是内部或外部命令,以管理员运行pycharm,再输入allure
结果:
在这里插入图片描述
再次执行命令

 allure serve ./result/tmp

在这里插入图片描述

5.报告验收

在这里插入图片描述

6.扩展-生成测试报告并且随时打开

生成报告

allure generate ./result/map -o ./result/tmp/ --clean

在这里插入图片描述
在这里插入图片描述

打开报告,启动一个tomcat服务,在服务下打开HTML页面

allure open -h xx.xx.xx.xx -p 8888 ./repore/tmp

在这里插入图片描述
ip获取方式

结果:
在这里插入图片描述

7.allure特性

@allure.feature(‘功能名称’)
@allure.stiry(‘子功能名称’)
@allure.step(‘步骤细节’)

@allure.feature("登录模块")
class TestLogin:
    @allure.story("登陆成功")
    def test_login_success(self):
        print("这是登录: 测试用例 ,登录成功 ")
        pass

    @allure.story("登陆成功-a")
    def test_login_success_a(self):
        print("这是登录: 测试用例 ,登录成功 ")
        pass

    @allure.story("用户名缺失")
    def test_login_success_b(self):
        print("用户名缺失 ")
        pass

    @allure.story("密码缺失")
    def test_login_failure(self):
        # 标记用例步骤
        with allure.step("点击用户名"):
            print("输入用户名 ")
        # 标记用例步骤
        with allure.step("点击密码"):
            print("输入密码 ")
        print("点击登录")
        while allure.step("点击之后登录失败"):
            assert '1' == 1
            print("登录失败")
        pass

    @allure.story("登录失败")
    def test_login_failure_a(self):
        print("这是登录: 测试用例 ,登录失败 ")
        pass

报告结果:
feature 对应模块
story 对应子模块
在这里插入图片描述

step对应用例步骤 代码中使用 with allure.step
在这里插入图片描述
@allure.link(“链接地址”,name=“描述”)

pytest pytest_allure_link.py --alluredir=./result/link

@allure.testcase(“用例地址”,“描述”)

pytest pytest_allure_link.py --alluredir=./result/link

@allure.issue(“bug id”,“描述”)

pytest pytest_allure_link.py --allure-link-pattern=issue:http://192.168.50.2:8081/bug-view-9663.html --alluredir=./result/link
# 链接地址
@allure.link("http://www.baidu.com", name="这是一个链接")
def test_with_link():
    print("这是一条加了链接的用例")


# 用例地址
TEST_CASE_LINK = "http://www.baidu.com"


@allure.testcase(TEST_CASE_LINK, "登录用例")
def test_with_link_2():
    print("这是一条加了链接的登录用例")


# bug链接 bug id
@allure.issue("9663", "这是一个issue")
def test_with_link_3():
    print("这是一条加了链接的登录用例")

生成报告结果:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
attack

def test_attach_text():
    allure.attach.file(text,
                       attachment_type=allure.attachment_type.TEXT)

def test_attach_html():
    allure.attach("<body>这是一段htmlbody</body>", "这是一个html测试块", attachment_type=allure.attachment_type.HTML)

def test_attach_picture():
    allure.attach.file("D:\JetBrains\PycharmProjects\wangmin\测试框架\ource\picture.jpg",
                       name="这是一个图片",
                       attachment_type=allure.attachment_type.JPG)

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

@allure.attach(‘具体文本信息’),需要附加的信息,可以提供数据、文本、图片、视频、网页
pytest 文件名 --allure-features’购物车功能’ --allure-storise ‘加入购物车’(注意这里–allure_features中间是下划线)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我其实是个新手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值