From 241f58b66f5a245c3dd85101dee052bba358bbc8 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 1 Mar 2022 16:36:48 +0100 Subject: stop `haketilo()` fixture cleanup from closing last browser window --- test/haketilo_test/conftest.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/haketilo_test/conftest.py b/test/haketilo_test/conftest.py index 834f026..eaee910 100644 --- a/test/haketilo_test/conftest.py +++ b/test/haketilo_test/conftest.py @@ -74,6 +74,16 @@ def driver(proxy, _driver, request): _driver.implicitly_wait(0) yield _driver +def safe_uninstall_addon(driver, addon_id): + """ + Unloading an extension might cause its windows to vanish. Make sure there's + at least one window navigated to some other page before uninstalling the + addon. Otherwise, we could be left with a windowless browser :c + """ + driver.switch_to.window(driver.window_handles[-1]) + driver.get('https://gotmyowndoma.in/') + driver.uninstall_addon(addon_id) + @pytest.fixture() def webextension(driver, request): ext_data = request.node.get_closest_marker('ext_data') @@ -97,13 +107,7 @@ def webextension(driver, request): yield - # Unloading an extension might cause its windows to vanish. Make sure - # there's at least one window navigated to some other page before - # uninstalling the addon. Otherwise, we could be left with a windowless - # browser :c - driver.switch_to.window(driver.window_handles[-1]) - driver.get('https://gotmyowndoma.in/') - driver.uninstall_addon(addon_id) + safe_uninstall_addon(driver, addon_id) ext_path.unlink() @pytest.fixture() @@ -113,7 +117,7 @@ def haketilo(driver): yield - driver.uninstall_addon(addon_id) + safe_uninstall_addon(driver, addon_id) script_injector_script = '''\ /* -- cgit v1.2.3