conftest.py (2099B)
1 import pytest 2 from webdriver.transport import HTTPWireProtocol 3 4 5 @pytest.fixture(name="configuration", scope="session") 6 def fixture_configuration(configuration): 7 """Remove "acceptInsecureCerts" from capabilities if it exists. 8 9 Some browser configurations add acceptInsecureCerts capability by default. 10 Remove it during new_session tests to avoid interference. 11 """ 12 if "acceptInsecureCerts" in configuration["capabilities"]: 13 configuration = dict(configuration) 14 del configuration["capabilities"]["acceptInsecureCerts"] 15 return configuration 16 17 18 @pytest.fixture(name="new_session") 19 def fixture_new_session(request, configuration, current_session): 20 """Start a new session for tests which themselves test creating new sessions. 21 22 :param body: The content of the body for the new session POST request. 23 24 :param delete_existing_session: Allows the fixture to delete an already 25 created custom session before the new session is getting created. This 26 is useful for tests which call this fixture multiple times within the 27 same test. 28 """ 29 custom_session = {} 30 31 transport = HTTPWireProtocol( 32 configuration["host"], 33 configuration["port"], 34 url_prefix="/", 35 ) 36 37 def _delete_session(session_id): 38 transport.send("DELETE", f"session/{session_id}") 39 40 def new_session(body, delete_existing_session=False, headers=None): 41 # If there is an active session from the global session fixture, 42 # delete that one first 43 if current_session is not None: 44 current_session.end() 45 46 if delete_existing_session: 47 _delete_session(custom_session["session"]["sessionId"]) 48 49 response = transport.send("POST", "session", body, headers=headers) 50 if response.status == 200: 51 custom_session["session"] = response.body["value"] 52 return response, custom_session.get("session", None) 53 54 yield new_session 55 56 if custom_session.get("session") is not None: 57 _delete_session(custom_session["session"]["sessionId"]) 58 custom_session = None