我试图以一种可以在conftest.py中实例化的方式启动硒Web驱动程序,同时还通过cli定义我正在使用的浏览器。
我正在使用本教程中的代码作为基础,但尝试使设置功能未硬编码为使用chrome,而是通过“ --driver chrome”或“ --driver firefox”运行文件 https://www.seleniumeasy.com/python/pytest-run-webdriver-tests-in-parallel
conftest.py
import pytest
from selenium import webdriver
@pytest.fixture(scope="session")
def setup(request):
print("Initiating selenium webdriver. . .")
session = request.node
for item in session.items:
cls = item.getparent(pytest.Class)
setattr(cls.obj, "driver", webdriver)
webdriver.get("http://seleniumeasy.com/test")
webdriver.maximize_window()
yield webdriver
webdriver.close()
test_file.py
import pytest
from selenium import webdriver
@pytest.mark.usefixtures("setup")
def test_title(self):
assert "Selenium Easy" in self.driver.title
我收到以下错误。
request = <SubRequest 'setup' for <Function test_title>>
@pytest.fixture(scope="session")
def setup(request):
print("Initiating selenium webdriver. . .")
session = request.node
for item in session.items:
cls = item.getparent(pytest.Class)
setattr(cls.obj, "driver", webdriver)
> webdriver.get("http://seleniumeasy.com/test")
E AttributeError: module 'selenium.webdriver' has no attribute 'get'
parallel-tests\conftest.py:21: AttributeError