Skip to content

Commit 2d31a75

Browse files
As per PR - #96 comments, Code Refactoring is implemented on below 4 files.
1 parent 89f15ac commit 2d31a75

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

pages/screening_subject_search/subject_screening_search_page.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class SubjectScreeningPage(BasePage):
1010
def __init__(self, page: Page):
1111
super().__init__(page)
1212
self.page = page
13+
self.results_table_locator = "table#subject-search-results"
14+
1315
# Subject Search Criteria - page filters
1416
self.episodes_filter = self.page.get_by_role("radio", name="Episodes")
1517
self.demographics_filter = self.page.get_by_role("radio", name="Demographics")
@@ -149,6 +151,7 @@ def select_dob_using_calendar_picker(self, date) -> None:
149151
CalendarPicker(self.page).v1_calender_picker(date)
150152

151153
def verify_date_of_birth_filter_input(self, expected_text: str) -> None:
154+
"""Verifies that the Date of Birth filter input field has the expected value."""
152155
expect(self.date_of_birth_filter).to_have_value(expected_text)
153156

154157

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import pytest
2-
from playwright.sync_api import Page, expect
2+
from playwright.sync_api import Page
33
from utils.user_tools import UserTools
44
from utils.table_util import TableUtils
55
from pages.base_page import BasePage
66
from utils.screening_subject_page_searcher import search_subject_by_surname
7+
from pages.screening_subject_search.subject_screening_search_page import (
8+
SubjectScreeningPage,
9+
)
710

811
@pytest.mark.regression
912
@pytest.mark.subject_search
@@ -12,7 +15,7 @@ def test_user_can_search_for_subject_and_results_are_returned(page: Page):
1215
Verify that User can log in to BCSS "England" as user role "Hub Manager - State Registered"
1316
Navigate it to the Subject Search Criteria Page & added value "S*" to the "Surname" search field
1417
Clicking on the search button on the subject search criteria page
15-
Then Some subject search criteria results are returned & paused to admire the view for "5" seconds
18+
Then Verifies that search results contain Surnames beginning with S
1619
"""
1720

1821
# Log in as Hub Manager - State Registered (England)
@@ -25,8 +28,7 @@ def test_user_can_search_for_subject_and_results_are_returned(page: Page):
2528
# click search button on the subject search criteria page
2629
search_subject_by_surname(page, "S*")
2730

28-
# Assert that some results are returned
29-
# Replace the below selector with the actual table locator if different
30-
table_locator = "table#subject-search-results" # Example CSS selector
31-
TableUtils(page, table_locator).assert_surname_in_table("S*")
32-
31+
# Assert that some results are returned with the surname starting with "S*"
32+
TableUtils(
33+
page, SubjectScreeningPage(page).results_table_locator
34+
).assert_surname_in_table("S*")

utils/table_util.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,22 @@ def get_cell_value(self, column_name: str, row_index: int) -> str:
238238
def assert_surname_in_table(self, surname_pattern):
239239
"""
240240
Asserts that a surname matching the given pattern exists in the table.
241-
242241
Args:
243242
surname_pattern (str): The surname or pattern to search for (supports '*' as a wildcard at the end).
244243
"""
245244
# Locate all surname cells (adjust selector as needed)
246-
surname_criteria = self.page.locator("//table//tr[position()>1]/td[2]") # Use the correct column index
245+
surname_criteria = self.page.locator(
246+
"//table//tr[position()>1]/td[3]"
247+
) # Use the correct column index
247248
if surname_pattern.endswith("*"):
248249
prefix = surname_pattern[:-1]
249-
found = any(cell.inner_text().startswith(prefix) for cell in surname_criteria.element_handles())
250+
found = any(
251+
cell.inner_text().startswith(prefix)
252+
for cell in surname_criteria.element_handles()
253+
)
250254
else:
251-
found = any(surname_pattern == cell.inner_text() for cell in surname_criteria.element_handles())
255+
found = any(
256+
surname_pattern == cell.inner_text()
257+
for cell in surname_criteria.element_handles()
258+
)
252259
assert found, f"No surname matching '{surname_pattern}' found in table."

utils/user_tools.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ def user_login(page: Page, username: str) -> None:
3636
raise ValueError("Environment variable 'BCSS_PASS' is not set")
3737
CognitoLoginPage(page).login_as_user(user_details["username"], password)
3838

39-
@staticmethod
40-
def login(page, user_role, region):
41-
# Implement login logic here
42-
pass
43-
4439
@staticmethod
4540
def get_subject_with_criteria(episode_type, episode_status, has_referral_date, has_diagnosis_date, diagnosis_date_reason):
4641
# Example implementation: fetch NHS number from a test data file based on criteria
@@ -59,8 +54,8 @@ def get_subject_with_criteria(episode_type, episode_status, has_referral_date, h
5954
subject.get("diagnosis_date_reason") == diagnosis_date_reason
6055
):
6156
return subject.get("nhs_number", "1234567890")
62-
# If no match found, return dummy NHS number
63-
return "1234567890"
57+
# If no match found, then exception is raised
58+
raise SubjectNotFoundError("No NHS number found using the provided criteria.")
6459

6560
@staticmethod
6661
def retrieve_user(user: str) -> dict:
@@ -85,3 +80,7 @@ def retrieve_user(user: str) -> dict:
8580

8681
class UserToolsException(Exception):
8782
pass
83+
84+
class SubjectNotFoundError(Exception):
85+
"""Raised when no subject matches the provided criteria."""
86+
pass

0 commit comments

Comments
 (0)