From e14a369d8085815ad77db905a1c90f7e2442c012 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 23 Oct 2023 14:14:28 -0400 Subject: [PATCH] Fix navigation error in Playwright tool tests. --- lib/tool_shed/test/base/playwrightbrowser.py | 18 +++++++++++++++++- lib/tool_shed/test/base/twilltestcase.py | 17 ++++++++++++++--- ...est_0030_repository_dependency_revisions.py | 2 +- ...est_0100_complex_repository_dependencies.py | 2 +- .../test_0420_citable_urls_for_repositories.py | 2 +- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/tool_shed/test/base/playwrightbrowser.py b/lib/tool_shed/test/base/playwrightbrowser.py index d29529cece24..d493e97aa990 100644 --- a/lib/tool_shed/test/base/playwrightbrowser.py +++ b/lib/tool_shed/test/base/playwrightbrowser.py @@ -27,7 +27,16 @@ def __init__(self, page: Page): self._page = page def visit_url(self, url: str, allowed_codes: List[int]) -> str: - response = self._page.goto(url) + try: + response = self._page.goto(url) + except Exception as e: + if "Navigation interrupted by another one" in str(e): + # I believe redirect on the target page interfering with + # this thread's test. + time.sleep(0.25) + response = self._page.goto(url) + else: + raise assert response is not None return_code = response.status assert return_code in allowed_codes, "Invalid HTTP return code {}, allowed codes: {}".format( @@ -167,6 +176,13 @@ def logout_if_logged_in(self, assert_logged_out=True): if assert_logged_out: self.expect_not_logged_in() + def explicit_logout(self): + self._page.wait_for_selector(Locators.toolbar_logout) + logout_locator = self._page.locator(Locators.toolbar_logout) + logout_locator.click() + self._page.wait_for_load_state("networkidle") + expect(self._page.locator(Locators.toolbar_logout)).not_to_be_visible() + def expect_not_logged_in(self): expect(self._page.locator(Locators.toolbar_logout)).not_to_be_visible() diff --git a/lib/tool_shed/test/base/twilltestcase.py b/lib/tool_shed/test/base/twilltestcase.py index e7d32c23e153..4eda8af0e268 100644 --- a/lib/tool_shed/test/base/twilltestcase.py +++ b/lib/tool_shed/test/base/twilltestcase.py @@ -749,6 +749,7 @@ def login( username: str = "admin-user", redirect: str = "", logout_first: bool = True, + explicit_logout: bool = False, ): if self.is_v2: # old version had a logout URL, this one needs to check @@ -757,7 +758,7 @@ def login( # Clear cookies. if logout_first: - self.logout() + self.logout(explicit=explicit_logout) # test@bx.psu.edu is configured as an admin user previously_created, username_taken, invalid_username = self.create( email=email, password=password, username=username, redirect=redirect @@ -786,9 +787,19 @@ def _playwright_browser(self) -> PlaywrightShedBrowser: def _page(self) -> Page: return self._playwright_browser._page - def logout(self): + def logout(self, explicit: bool = False): + """logout of the current tool shed session. + + By default this is a logout if logged in action, + however if explicit is True - ensure there is a session + and be explicit in logging out to provide extract test + structure. + """ if self.is_v2: - self._playwright_browser.logout_if_logged_in() + if explicit: + self._playwright_browser.explicit_logout() + else: + self._playwright_browser.logout_if_logged_in() else: self.visit_url("/user/logout") self.check_page_for_string("You have been logged out") diff --git a/lib/tool_shed/test/functional/test_0030_repository_dependency_revisions.py b/lib/tool_shed/test/functional/test_0030_repository_dependency_revisions.py index 8436d84d8794..6e2b6e3789ba 100644 --- a/lib/tool_shed/test/functional/test_0030_repository_dependency_revisions.py +++ b/lib/tool_shed/test/functional/test_0030_repository_dependency_revisions.py @@ -21,7 +21,7 @@ class TestRepositoryDependencyRevisions(ShedTwillTestCase): def test_0000_initiate_users(self): """Create necessary user accounts.""" self.login(email=common.test_user_1_email, username=common.test_user_1_name) - self.login(email=common.admin_email, username=common.admin_username) + self.login(email=common.admin_email, username=common.admin_username, explicit_logout=True) def test_0005_create_category(self): """Create a category for this test suite""" diff --git a/lib/tool_shed/test/functional/test_0100_complex_repository_dependencies.py b/lib/tool_shed/test/functional/test_0100_complex_repository_dependencies.py index fb7625860558..0dc0ff80762f 100644 --- a/lib/tool_shed/test/functional/test_0100_complex_repository_dependencies.py +++ b/lib/tool_shed/test/functional/test_0100_complex_repository_dependencies.py @@ -29,7 +29,7 @@ class TestComplexRepositoryDependencies(ShedTwillTestCase): def test_0000_initiate_users(self): """Create necessary user accounts.""" self.login(email=common.test_user_1_email, username=common.test_user_1_name) - self.login(email=common.admin_email, username=common.admin_username) + self.login(email=common.admin_email, username=common.admin_username, explicit_logout=True) def test_0005_create_bwa_package_repository(self): """Create and populate package_bwa_0_5_9_0100.""" diff --git a/lib/tool_shed/test/functional/test_0420_citable_urls_for_repositories.py b/lib/tool_shed/test/functional/test_0420_citable_urls_for_repositories.py index 0a46eec3fe7b..8ad59d24a10c 100644 --- a/lib/tool_shed/test/functional/test_0420_citable_urls_for_repositories.py +++ b/lib/tool_shed/test/functional/test_0420_citable_urls_for_repositories.py @@ -37,7 +37,7 @@ def test_0000_initiate_users(self): Previously created accounts will not be re-created. """ self.login(email=common.test_user_1_email, username=common.test_user_1_name) - self.login(email=common.admin_email, username=common.admin_username) + self.login(email=common.admin_email, username=common.admin_username, explicit_logout=True) def test_0005_create_repository(self): """Create and populate the filtering_0420 repository