zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python allure的介绍和使用(持续更新中)

Python 使用 介绍 更新 持续 Allure
2023-06-13 09:12:46 时间

大家好,又见面了,我是你们的朋友全栈君。

前言:是不是很意外,我又和大家见面了,这个章节咱们学习python allure的使用 1、allure 的介绍

2、allure 的报告概览

3、allure的安装

4、使用allure2生成更加精美的测试报告 pip install allure-pytest(安装这个辅助allure生成测试报告) pytest –alluredir=指定路径(指定allure报告数据生成路径) allure serve 报告路径(生成HTML报告,这个会直接在线打开报告) allure generate ./result/5 -o ./report/5/ –clean(指定生成报告的路径) allure open -h 127.0.0.1 -p 8888 ./report/5(启动本地服务生成链接查看报告)

5、allure常用的特性

6、@alllure.feature与@allure.store的关系

7、@allure.step()与with allure.step():的区别

8、allure 用issue与testcase关联

9、给测试用例划分优先级

10、给allure 测试报告添加内容(图片、附件、文本、截图、HTML等)

11、实战演练 实例1:

import pytest
import allure
@allure.feature("这是登录模块测试用例")
class Test_login():
    @allure.story("用户名正确,登录成功")
    @allure.severity(allure.severity_level.BLOCKER)     #阻塞
    def test_logina(self):
        allure.attach("这是一个纯文本",name="文本信息",attachment_type=allure.attachment_type.TEXT)    #添加文本
        print("这是登录,用户名正确,登录成功")
        pass

    @allure.story("密码正确,登录成功")
    @allure.severity(allure.severity_level.CRITICAL)    #严重
    def test_loginb(self):
        allure.attach("<body>这是一个网页</body>",name="HTML测试模块",attachment_type=allure.attachment_type.HTML)    #添加网页

        print("这是登录,密码正确,登录成功")
        pass

    @allure.story("用户名错误,登录失败")
    # --allure-link-pattern=issue:https://blog.csdn.net/weixin_44275820/article/details/105169871/issue/{}
    @allure.issue("10086","这是一个bug,需要修复")
    @allure.severity(allure.severity_level.NORMAL)    #正常问题
    def test_loginc(self):
        allure.attach.file("./picture/微信头像.jpg",name="这是一个图片",attachment_type=allure.attachment_type.JPG)    #添加图片
        print("这是登录,用户名错误,登录失败")
        pass

    @allure.story("密码错误,登录失败")
    @allure.link("https://blog.csdn.net/weixin_44275820/article/details/105169871",name="我的博客")
    @allure.severity(allure.severity_level.MINOR)    #不太重要
    def test_logind(self):
        with allure.step("点击用户名输入框"):
            print("输入用户名")
        with allure.step("点击输入密码输入框"):
            print("输入密码")
        print("点击登录按钮")
        with allure.step("点击登录后登录失败"):
            assert "1" == 1
            print("这是登录,密码错误,登录失败")
        pass

    Testcase_link = "https://blog.csdn.net/weixin_44275820/article/details/105169871"
    @allure.story("用户不存在,登录失败")
    @allure.testcase(Testcase_link,"我的博客管理平台")
    @allure.severity(allure.severity_level.TRIVIAL)    #不重要
    def test_logine(self):
        print("这是登录,用户不存在,请重新注册")
        pass

    @allure.story("密码已锁定,登录失败")
    def test_loginf(self):
        print("这是登录,密码已锁定,请重置密码")
        pass

    @allure.story("密码为空,登录失败")
    def test_loging(self):
        print("这是登录,密码为空,请输入密码")
        pass

if __name__ =='__main__':
    pytest.main("-v -s")

实例2:

import pytest
import allure
import time
from selenium import webdriver

Testcase_link1 = "https://www.baidu.com"
@allure.testcase(Testcase_link1,"百度,你值得拥有")
@allure.feature("百度搜索")
@pytest.mark.parametrize("search_data",["奔驰","宝马","保时捷"])
def test_search(search_data):

    with allure.step("打开百度网页"):
        driver = webdriver.chrome("C:\\Users\liwenliang\AppData\Local\Google\Chrome\Application\chrome.exe")
        driver.get("https://www.baidu.com")

    with allure.step(f"输入搜索词",{Testcase_link1}):
        driver.find_element_by_id("KW").send_keys(search_data)
        time.sleep(3)
        driver.find_element_by_id("SU").click()
        time.sleep(3)

    with allure.step("保存图片"):
        driver.save_screenshot("./result/b.png")
        allure.attach.file("./result/b.png",name="这是保存的图片",attachment_type=allure.attachment_type.PNG)

    with allure.step("关闭浏览器"):
        driver.quit()

if __name__ =='__main__':
    pytest.main("-v -s")

12、数据驱动 数据驱动分为源数据驱动和步骤数据驱动

13、数据驱动的逻辑

我们这里直接用yaml做数据驱动,yaml的基础资料请看一下网址: https://www.ruanyifeng.com/blog/2016/07/yaml.html https://yaml.org/spec/1.1/#id857168 1 https://pyyaml.org/wiki/PyYAMLDocumentation

def data():
    with open("test_data.yaml") as f:
        yaml.load(f)

14、allure2的解析过程 安装allure2 生成allure测试结果 pytest –alluredir=allure . 展示报告 allure serve allure/ 生成最终版本的报告 allure generate allure/ 使用allure2提供的api,增强报告 截图、录像、日志、链接、步骤

更新。。。。。。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164419.html原文链接:https://javaforall.cn