I’m trying to set up a pytest-bdd splinter test automation framework.
I have three scenarios in a feature file and the related steps definitions in a .py file.
In my conftest.py file I’m trying to use hooks for scenario setup and teardown.
I’m wanting to open chrome and navigate to the URL in the scenario setup and close chrome in the scenario teardown. So each scenario starts from a position of chrome not being open.
It works fine for the first scenario. Chrome opens, navigates to the URL and the scenario from the feature file runs and passes and then chrome closes.
The second and third scenarios fail with:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=57918): Max retries exceeded with url: /session/60a9e9ff53deb3f8a77fd1dbdfd1ba92/url (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001D67EF33090>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
Here’s the conftest.py code
"""conftest"""
import pytest
from splinter import Browser, Config
APP_URL = "https://webapp_url"
browser_config = Config(fullscreen=True)
browser = Browser('chrome', config=browser_config)
@pytest.hookimpl
def pytest_bdd_before_scenario(scenario):
"""scenario set up tasks"""
print("Before scenario: " + str(scenario.name))
browser.visit(APP_URL)
@pytest.hookimpl
def pytest_bdd_after_scenario(scenario):
"""scenario clean tasks"""
print("After scenario: " + str(scenario.name))
browser.quit()
From what I understand the browser.quit() line closes the browser but for some reason the browser doesn’t open for scenario 2 and 3. I thought that perhaps browser.quit() is ending the session which is then not re-initiated and tried to re-initiate it but that didn’t work, or at least my attempt didn’t work.
I’ve checked some of the WinError 10061 posts and they mostly are caused by driver.quit() appearing twice which isn’t exactly the case here.
I suspect my understanding of python and pytest are letting me down here.
What am I missing?
On3Pl4te is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.