ERROR test_selenium_pytest.py::test_web - _pytest.config.exceptions.UsageError: --driver must be spe

def test_web(selenium):
    selenium.get("https://www.baidu.com")
    assert 1 == 2

终端直接运行测试用例:

(.venv) PS C:\Users\batytao\PycharmProjects\PythonProject> pytest --driver Edge --html report.html  (注:pytest 执行的文件名的前缀是test,则pytest 可以不跟文件名,如果前缀不是test,则需跟文件名,如: pytest selenium_pytest.py --driver Edge --html report.html  )

提示错误:ERROR test_selenium_pytest.py::test_web - _pytest.config.exceptions.UsageError: --driver must be specified

解决:

这个错误表明在使用Selenium+Pytest进行Web自动化测试时,没有正确指定浏览器驱动(driver)参数。

实测验证ok:

from selenium import webdriver
from selenium.webdriver.edge.service import Service

def test_web():
    # 指定驱动路径
    service = Service(executable_path=r'C:\Program Files\edgedriver\MicrosoftWebDriver.exe')

    # 添加detach选项防止浏览器闪退
    options = webdriver.EdgeOptions()
    options.add_experimental_option("detach", True)

    driver = webdriver.Edge(options=options, service=service)
    driver.get("https://www.baidu.com")

    assert 1 == 1
    driver.quit()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

BatyTao

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

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

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

打赏作者

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

抵扣说明:

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

余额充值