selenium之pytest allure生成测试报告

在这里插入图片描述
https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.7.0/
windows下载版本:
在这里插入图片描述
解压后添加到环境变量:
E:\Program Files\allure-2.7.0\allure-2.7.0\bin

在这里插入图片描述
代码:

#pytest生成测试报告
import allure
import pytest

@pytest.fixture(scope="session")
def login():
    print("用例先登录")

@allure.step("步骤1:点xxx")
def step_1():
    print("111")

@allure.step("步骤2:点xxx")
def step_2():
    print("222")

@allure.feature("编辑页面")
class TestEditPage():
    """编辑页面"""

    @allure.story("这是一个xxx的用例")
    def test1(self,login):
        """用例描述 先登录再执行story的用例"""
        step_1()
        step_2()
        print("这是一个xxx的用例")

    @allure.story("打开a页面")
    def test2(self,login):
        """用例描述:先执行fixcure的登录然后再执行yyy"""
        print("yyy")

if __name__ == '__main__':
    #注意生成测试报告必须在命令行执行
    # 所以执行时要切换到seelenium_projrct目录下去
    #pytest --alluredir ./reports testcases/pytest/test08.py  生成测试报告存放到路径reports目录下
    # 所以执行时要切换到seelenium_projrct目录下去
    #allure serve ./reports  启动allure 查看报告

    pytest.main(['--alluredir' './reports' 'test08.py'])
    pytest.main(['--alluredir' './reports' 'test08.py'])





#注意生成测试报告必须在命令行执行
# 所以执行时要切换到seelenium_projrct目录下去
#pytest --alluredir ./reports testcases/pytest/test08.py  生成测试报告存放到路径reports目录下
# 所以执行时要切换到seelenium_projrct目录下去
#allure serve ./reports  启动allure 查看报告

C:\Users\Administrator\pythonxiangmu\seelenium_project>pytest --alluredir ./reports testcases/pytest/test08.py

执行结果;
在这里插入图片描述

C:\Users\Administrator\pythonxiangmu\seelenium_project>allure serve ./reports
执行结果:
在这里插入图片描述

Python结合SeleniumpytestAllure可以创建强大的Web端自动化测试流程。以下是这个组合的工作方式: 1. **Selenium**[^1]: 是一个用于Web应用程序自动化测试的开源库,它允许你模拟用户在浏览器上的交互,如点击按钮、填写表单等。通过Selenium,你可以编写Python脚本来控制浏览器的行为。 2. **pytest**: 是一个流行的测试框架,以其简洁的语法和丰富的插件生态系统著称。它能更方便地编写测试用例,比如断言、参数化测试等。 3. **Allure**[^2]: 是一个报告工具,用于生成详细的测试报告,包括测试执行过程的可视化图表和详细的测试结果描述。这有助于团队更好地理解和跟踪测试状态。 4. **Jenkins**: 是一个持续集成/持续部署(CI/CD)服务器,它可以集成pytestAllure,自动运行测试并生成报告,从而实现自动化测试的持续执行。 具体操作流程如下: 1. 安装必要的库(如Selenium WebDriver、pytestpytest-seleniumallure-pytest等)。 2. 使用pytest编写测试用例,比如: ```python def test_login(self, driver): driver.get("http://example.com/login") username_input = driver.find_element_by_name("username") username_input.send_keys("test_user") password_input = driver.find_element_by_name("password") password_input.send_keys("test_password") password_input.submit() ``` 3. 使用pytest-selenium标记测试为Selenium测试: ```python import pytest_selenium @pytest.mark.selenium def test_login_with_selenium(driver): ... ``` 4. 在pytest配置中设置Allure插件: ```python pytest_plugins = ["allure_pytest"] ``` 5. 在Jenkins中配置一个job,连接到Allure服务器,每次构建后自动上传测试报告
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值