Skip to content

Commit

Permalink
Fix navigation error in Playwright tool tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 24, 2023
1 parent 0d74680 commit e14a369
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
18 changes: 17 additions & 1 deletion lib/tool_shed/test/base/playwrightbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()

Expand Down
17 changes: 14 additions & 3 deletions lib/tool_shed/test/base/twilltestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -757,7 +758,7 @@ def login(

# Clear cookies.
if logout_first:
self.logout()
self.logout(explicit=explicit_logout)
# [email protected] is configured as an admin user
previously_created, username_taken, invalid_username = self.create(
email=email, password=password, username=username, redirect=redirect
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e14a369

Please sign in to comment.