python+selenium(7)---pytest+allure生成测试报告

本文介绍了如何利用Python的pytest框架和allure库来创建测试报告。首先,下载并安装allure,将其bin目录添加到Path环境变量。接着,通过pip安装pytest和allure-pytest。然后,运行测试用例,使用--alluredir参数指定报告的保存位置。最后,通过allure generate命令生成HTML报告,并在浏览器中查看。

1.下载安装allure

下载合适版本 https://github.com/allure-framework/allure2/releases,下载了2.13.0版本

解压文件并将 bin目录添加到Path环境变量中

验证allure:输入allure --version,返回版本信息则安装成功

2.安装pytest和allure-pytest

pip install pytest

pip install allure-pytest

3.执行测试用例

在项目根目录下执行如下命令,就会执行Test.py模块中的用例,生成report文件里面存放的是后面报告需要解析的json文件,包含了用例的所有信息。

执行这个Test.py模块下的用例,--alluredir=report 生成report目录存放数据,--clean-alluredir 清除原有的存放数据路径

pytest .\Test.py --alluredir=report --clean-alluredir

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服务器,每次构建后自动上传测试报告
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值