Google has failed me in a search for answers so I am turning here.
I am setting up an automated web testing suite using pytest and selenium. I would like to code to first check for updates to chromewebdriver before running the tests. I figured the best way to do this was using fixtures and the webdriver_manager module.
I started with the following and it worked
@pytest.fixture()
def chrome_driver_init(request):
driver = webdriver.Chrome(options=opts, executable_path=ChromeDriverManager(path=TEST_PATH).install())
request.cls.driver = driver
driver.get(URL)
driver.maximize_window()
yield
driver.quit()
but having to check for any webdriver updates for every test is really slowing things down. So I attempted this but cant figure out how to get the child fixture to use the variable from the parent one. I would really like it to only run the update once and the child use the variable from then on without calling the update parent again.
#Checks for latest ChromeDriver version
@pytest.fixture(scope='session')
def update_chrome_driver():
chrome_driver = webdriver.Chrome(options=opts, executable_path=ChromeDriverManager(path=TEST_PATH).install())
return chrome_driver
#Initalizes chrome driver and opens testing window, runs at the beginning of each test
#Closes test window at end of test
@pytest.fixture(scope='class')
def chrome_driver_init(request, update_chrome_driver):
driver = update_chrome_driver
request.cls.driver = driver
driver.get(URL)
driver.maximize_window()
yield
driver.quit()
I have tried different combos of scope for the two fixtures but eventually the test set up fails. Anyone know a clean way to get this to work?