Skip to content

Commit 70e6f63

Browse files
Merge branch 'main' of github.com:NHSDigital/bcss-playwright into feature/BCSS-20521-c6-investigation-dataset-navigation-util
# Conflicts: # tests/smokescreen/test_compartment_6.py
2 parents a2aa6dd + 795a4db commit 70e6f63

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

pages/base_page.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class BasePage:
77

88
def __init__(self, page: Page):
99
self.page = page
10+
# Homepage - vars
11+
self.main_menu_string = "Main Menu"
1012
# Homepage/Navigation Bar links
1113
self.sub_menu_link = self.page.get_by_role("link", name="Show Sub-menu")
1214
self.hide_sub_menu_link = self.page.get_by_role("link", name="Hide Sub-menu")
@@ -16,7 +18,7 @@ def __init__(self, page: Page):
1618
self.refresh_alerts_link = self.page.get_by_role("link", name="Refresh alerts")
1719
self.user_guide_link = self.page.get_by_role("link", name="User guide")
1820
self.help_link = self.page.get_by_role("link", name="Help")
19-
self.main_menu_link = self.page.get_by_role("link", name="Main Menu")
21+
self.main_menu_link = self.page.get_by_role("link", name=self.main_menu_string)
2022
self.log_out_link = self.page.get_by_role("link", name="Log-out")
2123
# Main menu - page links
2224
self.contacts_list_page = self.page.get_by_role("link", name="Contacts List")
@@ -54,8 +56,33 @@ def __init__(self, page: Page):
5456

5557
def click_main_menu_link(self) -> None:
5658
"""Click the Base Page 'Main Menu' link if it is visible."""
57-
if self.main_menu_link.is_visible():
58-
self.click(self.main_menu_link)
59+
loops = 0
60+
text = None
61+
62+
while loops <= 3:
63+
if self.main_menu_link.is_visible():
64+
self.click(self.main_menu_link)
65+
try:
66+
if self.main_menu__header.is_visible():
67+
text = self.main_menu__header.text_content()
68+
else:
69+
text = None
70+
except Exception as e:
71+
logging.warning(f"Could not read header text: {e}")
72+
text = None
73+
74+
if text and self.main_menu_string in text:
75+
return # Success
76+
else:
77+
logging.warning("Main Menu click failed, retrying after 0.2 seconds")
78+
# The timeout is in place here to allow the page ample time to load if it has not already been loaded
79+
self.page.wait_for_timeout(200)
80+
81+
loops += 1
82+
# All attempts failed
83+
raise RuntimeError(
84+
f"Failed to navigate to Main Menu after {loops} attempts. Last page title was: '{text or 'unknown'}'"
85+
)
5986

6087
def click_log_out_link(self) -> None:
6188
"""Click the Base Page 'Log-out' link."""
@@ -100,8 +127,11 @@ def bowel_cancer_screening_system_header_is_displayed(self) -> None:
100127
)
101128

102129
def main_menu_header_is_displayed(self) -> None:
103-
"""Asserts that the Main Menu header is displayed."""
104-
expect(self.main_menu__header).to_contain_text("Main Menu")
130+
"""
131+
Asserts that the Main Menu header is displayed.
132+
self.main_menu_string contains the string 'Main Menu'
133+
"""
134+
expect(self.main_menu__header).to_contain_text(self.main_menu_string)
105135

106136
def bowel_cancer_screening_page_title_contains_text(self, text: str) -> None:
107137
"""Asserts that the page title contains the specified text.

pages/datasets/investigation_dataset_page.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class PractitionerOptions(StrEnum):
242242

243243
class TestingClinicianOptions(StrEnum):
244244
"""Enum for testing clinician options"""
245+
__test__ = False
245246

246247
BORROWING_PROPERTY = "886"
247248
CLAUSE_CHARTING = "918"

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ markers =
3434
compartment3: only for compartment 3
3535
compartment4: only for compartment 4
3636
compartment5: only for compartment 5
37+
compartment6: only for compartment 6
3738
compartment1_plan_creation: to run the plan creation for compartment 1
3839
vpn_required: for tests that require a VPN connection

0 commit comments

Comments
 (0)