您可以使用pip安装Selenium WebDriver:
```
pip install selenium
```
3. 安装pytest
您可以使用pip安装pytest:
```
pip install pytest
```
4. 安装pytest-xdist
pytest-xdist是一个pytest插件,用于并行运行测试。您可以使用以下命令安装:
```
pip install pytest-xdist
```
5. 安装pytest-rerunfailures
pytest-rerunfailures是一个pytest插件,用于运行失败的测试用例。您可以使用以下命令安装:
```
pip install pytest-rerunfailures
```
6. 安装pytest-html
pytest-html是一个pytest插件,用于生成HTML测试报告。您可以使用以下命令安装:
```
pip install pytest-html
```
7. 安装allure-pytest
allure-pytest是一个pytest插件,用于生成Allure测试报告。您可以使用以下命令安装:
```
pip install allure-pytest
8. 安装allure,并配置环境变量
8.1 allure官方地址:Central Repository: io/qameta/allure/allure-commandline (apache.org)
8.2 配置环境变量:进入 高级系统设置 - 环境变量 - 系统变量 - path - 编辑。[复制自己本地的bin目录,eg:D:\Python3.8\Scripts\allure-2.13.2\bin]
9. 修改pycharm的allure环境变量配置:
File --> Setting --> Bulid,Execution,Deployment --> Consonle -->Python Console:
[复制自己本地的bin目录,egEnvironment variables:PATH=D:\Python3.8\Scripts\allure-2.13.2\bin]
例子:
1. 创建一个名为test_example.py的文件,并编写测试用例。以下是一个示例:
```
import pytest
from selenium import webdriver
@pytest.mark.parametrize("search_text", ["Python", "Selenium", "pytest"])
def test_search(search_text):
driver = webdriver.Chrome()
driver.get("https://www.google.com/")
search_box = driver.find_element_by_name("q")
search_box.send_keys(search_text)
search_box.submit()
assert search_text in driver.title
driver.quit()
```
在这个例子中,我们编写了一个名为test_search的测试用例,并使用pytest.mark.parametrize装饰器实现了数据驱动。
2. 运行测试用例
使用以下命令运行测试用例:
```
pytest -n 3 --reruns 2 --html=report.html --alluredir=allure-results
```
上述命令将运行测试用例,并使用3个进程并行运行测试。如果测试失败,它将重试2次。它还将生成一个HTML测试报告,并将Allure测试报告输出到allure-results目录中。
3. 生成Allure测试报告
使用以下命令生成Allure测试报告:
```
allure serve allure-results