Skip to content

Commit 4f82c28

Browse files
Andyg79adrianoaru-nhsvictor-soares-ibm
authored
Refactoring reports_page and test_reports_page (2nd Attempt) (#19)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description refactor reports pages and tests <!-- Describe your changes in detail. --> ## Context The reports pages have a lot of different locators that perform the same function. I have removed locators and test data from the tests and added them to the page object, and created a function for clicking on NHS number links. <!-- Why is this change required? What problem does it solve? --> ## Type of changes The tests are generally cleaner and more readable. All of the tests can now call the same function to click on an NHS number link. <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [x] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [x] I have followed the code style of the project - [x] I have added tests to cover my changes (where appropriate) - [x] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes. --------- Co-authored-by: adrianoaru-nhs <[email protected]> Co-authored-by: victor-soares-ibm <[email protected]> Co-authored-by: Adriano Aru <[email protected]>
1 parent aaba148 commit 4f82c28

File tree

2 files changed

+177
-116
lines changed

2 files changed

+177
-116
lines changed

pages/reports/reports_page.py

Lines changed: 107 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,92 +6,131 @@ class ReportsPage(BasePage):
66
def __init__(self, page):
77
super().__init__(page)
88
self.page = page
9+
910
# Reports page main menu links
10-
self.bureau_reports_page = self.page.get_by_role("link", name="Bureau Reports")
11-
self.failsafe_reports_page = self.page.get_by_role(
11+
self.bureau_reports_link = self.page.get_by_text("Bureau Reports")
12+
self.failsafe_reports_link = self.page.get_by_role(
1213
"link", name="Failsafe Reports"
1314
)
14-
self.operational_reports_page = self.page.get_by_role(
15+
self.operational_reports_link = self.page.get_by_role(
1516
"link", name="Operational Reports"
1617
)
17-
self.strategic_reports_page = self.page.get_by_role(
18+
self.strategic_reports_link = self.page.get_by_role(
1819
"link", name="Strategic Reports"
1920
)
20-
self.cancer_waiting_times_reports_page = self.page.get_by_role(
21+
self.cancer_waiting_times_reports_link = self.page.get_by_role(
2122
"link", name="Cancer Waiting Times Reports"
2223
)
23-
self.dashboard = self.page.get_by_role("link", name="Dashboard")
24-
self.qa_report_dataset_completion_page = self.page.get_by_role(
24+
self.dashboard_link = self.page.get_by_role("link", name="Dashboard")
25+
self.qa_report_dataset_completion_link = self.page.get_by_role(
2526
"link", name="QA Report : Dataset Completion"
2627
)
27-
# Reports pages shared buttons & links
28+
29+
# Reports pages shared buttons, locators & links
2830
self.refresh_page_button = self.page.get_by_role("button", name="Refresh")
31+
self.reports_update_button = self.page.get_by_role("button", name="Update")
32+
self.report_start_date_field = self.page.get_by_role(
33+
"textbox", name="Report Start Date"
34+
)
35+
self.qa_report_dataset_completion_link = self.page.get_by_text(
36+
"QA Report : Dataset Completion"
37+
)
38+
39+
# Generate Report button locators
2940
self.generate_report_button = self.page.get_by_role(
3041
"button", name="Generate Report"
3142
)
32-
self.reports_update_button = self.page.get_by_role("button", name="Update")
33-
self.report_timestamp_element = self.page.locator("b")
43+
self.operational_reports_sp_appointments_generate_report_button = (
44+
self.page.locator("#submitThisForm")
45+
)
46+
47+
# Set patients screening centre dropdown locators
3448
self.set_patients_screening_centre_dropdown = self.page.locator(
3549
"#cboScreeningCentre"
3650
)
51+
self.six_weeks_availability_not_set_up_set_patients_screening_centre_dropdown = self.page.get_by_label(
52+
"Screening Centre"
53+
)
54+
self.practitioner_appointments_set_patients_screening_centre_dropdown = (
55+
page.get_by_label("Screening Centre")
56+
)
57+
self.attendance_not_updated_set_patients_screening_centre_dropdown = (
58+
page.get_by_label("Screening Centre")
59+
)
60+
61+
# Select screening practitioner dropdown locators
62+
self.screening_practitioner_dropdown = self.page.locator("#A_C_NURSE")
63+
64+
# Report Timestamp locators
65+
self.common_report_timestamp_element = self.page.locator("b")
66+
self.subject_ceased_report_timestamp_element = self.page.locator(
67+
"#displayGenerateDate > tbody > tr > td > b"
68+
)
69+
self.fobt_logged_not_read_report_timestamp_element = self.page.locator(
70+
"#report-generated"
71+
)
72+
self.six_weeks_availability_not_set_up_report_timestamp_element = (
73+
self.page.locator("#displayGenerateDate")
74+
)
3775

3876
# Failsafe Reports menu links
39-
self.date_report_last_requested_page = self.page.get_by_role(
77+
self.date_report_last_requested_link = self.page.get_by_role(
4078
"link", name="Date Report Last Requested"
4179
)
42-
self.screening_subjects_with_inactive_open_episode_link_page = (
43-
self.page.get_by_role("link", name="Screening Subjects With")
80+
self.screening_subjects_with_inactive_open_episode_link = self.page.get_by_role(
81+
"link", name="Screening Subjects With"
4482
)
45-
self.subjects_ceased_due_to_date_of_birth_changes_page = self.page.get_by_role(
83+
self.subjects_ceased_due_to_date_of_birth_changes_link = self.page.get_by_role(
4684
"link", name="Subjects Ceased Due to Date"
4785
)
48-
self.allocate_sc_for_patient_movements_within_hub_boundaries_page = (
86+
self.allocate_sc_for_patient_movements_within_hub_boundaries_link = (
4987
self.page.get_by_role(
5088
"link", name="Allocate SC for Patient Movements within Hub Boundaries"
5189
)
5290
)
53-
self.allocate_sc_for_patient_movements_into_your_hub_page = (
91+
self.allocate_sc_for_patient_movements_into_your_hub_link = (
5492
self.page.get_by_role(
5593
"link", name="Allocate SC for Patient Movements into your Hub"
5694
)
5795
)
58-
self.identify_and_link_new_gp_page = self.page.get_by_role(
96+
self.identify_and_link_new_gp_link = self.page.get_by_role(
5997
"link", name="Identify and link new GP"
6098
)
99+
61100
# Operational Reports menu links
62-
self.appointment_attendance_not_updated_page = self.page.get_by_role(
101+
self.appointment_attendance_not_updated_link = self.page.get_by_role(
63102
"link", name="Appointment Attendance Not"
64103
)
65-
self.fobt_kits_logged_but_not_read_page = self.page.get_by_role(
104+
self.fobt_kits_logged_but_not_read_link = self.page.get_by_role(
66105
"link", name="FOBT Kits Logged but Not Read"
67106
)
68-
self.demographic_update_inconsistent_with_manual_update_page = (
107+
self.demographic_update_inconsistent_with_manual_update_link = (
69108
self.page.get_by_role("link", name="Demographic Update")
70109
)
71-
self.screening_practitioner_6_weeks_availability_not_set_up_report_page = (
110+
self.screening_practitioner_6_weeks_availability_not_set_up_report_link = (
72111
page.get_by_role("link", name="Screening Practitioner 6")
73112
)
74-
self.screening_practitioner_appointments_page = self.page.get_by_role(
113+
self.screening_practitioner_appointments_link = self.page.get_by_role(
75114
"link", name="Screening Practitioner Appointments"
76115
)
77116

78-
# Reports page main menu links
117+
# Reports page main menu navigation
79118
def go_to_failsafe_reports_page(self) -> None:
80-
self.click(self.failsafe_reports_page)
119+
self.click(self.failsafe_reports_link)
81120

82121
def go_to_operational_reports_page(self) -> None:
83-
self.click(self.operational_reports_page)
122+
self.click(self.operational_reports_link)
84123

85124
def go_to_strategic_reports_page(self) -> None:
86-
self.click(self.strategic_reports_page)
125+
self.click(self.strategic_reports_link)
87126

88127
def go_to_cancer_waiting_times_reports_page(self) -> None:
89-
self.click(self.cancer_waiting_times_reports_page)
128+
self.click(self.cancer_waiting_times_reports_link)
90129

91130
def go_to_dashboard(self) -> None:
92-
self.click(self.dashboard)
131+
self.click(self.dashboard_link)
93132

94-
# Reports pages shared buttons actions
133+
# Reports pages shared buttons and actions
95134
def click_refresh_button(self) -> None:
96135
self.click(self.refresh_page_button)
97136

@@ -103,41 +142,69 @@ def click_reports_pages_update_button(self) -> None:
103142

104143
# Failsafe Reports menu links
105144
def go_to_date_report_last_requested_page(self) -> None:
106-
self.click(self.date_report_last_requested_page)
145+
self.click(self.date_report_last_requested_link)
107146

108147
def go_to_screening_subjects_with_inactive_open_episode_link_page(self) -> None:
109-
self.click(self.screening_subjects_with_inactive_open_episode_link_page)
148+
self.click(self.screening_subjects_with_inactive_open_episode_link)
110149

111150
def go_to_subjects_ceased_due_to_date_of_birth_changes_page(self) -> None:
112-
self.click(self.subjects_ceased_due_to_date_of_birth_changes_page)
151+
self.click(self.subjects_ceased_due_to_date_of_birth_changes_link)
113152

114153
def go_to_allocate_sc_for_patient_movements_within_hub_boundaries_page(
115154
self,
116155
) -> None:
117-
self.click(self.allocate_sc_for_patient_movements_within_hub_boundaries_page)
156+
self.click(self.allocate_sc_for_patient_movements_within_hub_boundaries_link)
118157

119158
def go_to_allocate_sc_for_patient_movements_into_your_hub_page(self) -> None:
120-
self.click(self.allocate_sc_for_patient_movements_into_your_hub_page)
159+
self.click(self.allocate_sc_for_patient_movements_into_your_hub_link)
121160

122161
def go_to_identify_and_link_new_gp_page(self) -> None:
123-
self.click(self.identify_and_link_new_gp_page)
162+
self.click(self.identify_and_link_new_gp_link)
124163

125164
# Operational Reports menu links
126165
def go_to_appointment_attendance_not_updated_page(self) -> None:
127-
self.click(self.appointment_attendance_not_updated_page)
166+
self.click(self.appointment_attendance_not_updated_link)
128167

129168
def go_to_fobt_kits_logged_but_not_read_page(self) -> None:
130-
self.click(self.fobt_kits_logged_but_not_read_page)
169+
self.click(self.fobt_kits_logged_but_not_read_link)
131170

132171
def go_to_demographic_update_inconsistent_with_manual_update_page(self) -> None:
133-
self.click(self.demographic_update_inconsistent_with_manual_update_page)
172+
self.click(self.demographic_update_inconsistent_with_manual_update_link)
134173

135174
def go_to_screening_practitioner_6_weeks_availability_not_set_up_report_page(
136175
self,
137176
) -> None:
138177
self.click(
139-
self.screening_practitioner_6_weeks_availability_not_set_up_report_page
178+
self.screening_practitioner_6_weeks_availability_not_set_up_report_link
140179
)
141180

142181
def go_to_screening_practitioner_appointments_page(self) -> None:
143-
self.click(self.screening_practitioner_appointments_page)
182+
self.click(self.screening_practitioner_appointments_link)
183+
184+
def click_nhs_number_link(self, page: Page) -> None:
185+
"""
186+
Clicks the first NHS number link present on the screen if any are found.
187+
"""
188+
# List of locators to check for NHS number links.
189+
# This implementation is a workaround for the fact that the NHS number
190+
# links are not using the same locators accross bcss
191+
# This is a temporary solution until
192+
# we have a table utility that will allow us to interact with tables across bcss.
193+
locators = [
194+
"#listReportDataTable > tbody > tr:nth-child(3) > td:nth-child(1) > a",
195+
"//*[@id='listReportDataTable']/tbody/tr[3]/td[1]",
196+
"//*[@id='listReportDataTable']/tbody/tr[3]/td[2]",
197+
"#listReportDataTable > tbody > tr:nth-child(3) > td:nth-child(1) > a",
198+
"#subjInactiveOpenEpisodes > tbody > tr:nth-child(1) > td.NHS_NUMBER.dt-type-numeric > a",
199+
]
200+
201+
for locator_string in locators:
202+
try:
203+
# Use page.locator to get a locator object
204+
locator = page.locator(locator_string)
205+
# Check if the locator is visible
206+
if locator.is_visible():
207+
# Click the locator
208+
locator.click()
209+
except Exception:
210+
print("No NHS number links found on the page")

0 commit comments

Comments
 (0)