Skip to content

Commit 94896e9

Browse files
vidhya-chandra1Andyg79
authored andcommitted
Code Refactoring is Implemented for JIRA Ticket - https://nhsd-jira.d… (#96)
BCSS-20611 - Selenium to Playwright - Regression Tests - Subject - Subject Search <!-- markdownlint-disable-next-line first-line-heading --> ## Description Selenium to Playwright - Regression Tests - Subject - Subject Search <!-- Describe your changes in detail. --> ## Context <!-- Why is this change required? What problem does it solve? --> Feature: Subject Search Screen Scenario: User can search for a subject and results are returned (#?) Given I log in to BCSS "England" as user role "Hub Manager - State Registered" When I navigate to the Subject Search Criteria Page And I add value "S*" to the "Surname" search field And I click the search button on the subject search criteria page Then Some subject search criteria results are returned ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [X] Refactoring (non-breaking change) - [X] 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) - [ ] 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.
1 parent 2f94da2 commit 94896e9

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pytest
2+
from playwright.sync_api import Page
3+
from utils.user_tools import UserTools
4+
from utils.table_util import TableUtils
5+
from pages.base_page import BasePage
6+
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+
)
10+
11+
@pytest.mark.regression
12+
@pytest.mark.subject_search
13+
def test_user_can_search_for_subject_and_results_are_returned(page: Page):
14+
"""
15+
Verify that User can log in to BCSS "England" as user role "Hub Manager - State Registered"
16+
Navigate it to the Subject Search Criteria Page & added value "S*" to the "Surname" search field
17+
Clicking on the search button on the subject search criteria page
18+
Then Verifies that search results contain Surnames beginning with S
19+
"""
20+
21+
# Log in as Hub Manager - State Registered (England)
22+
UserTools.user_login(page, "Hub Manager State Registered at BCS01")
23+
24+
# Navigate to the Subject Search Criteria Page
25+
BasePage(page).go_to_screening_subject_search_page()
26+
27+
# Add value "S*" to the "Surname" search field
28+
# click search button on the subject search criteria page
29+
search_subject_by_surname(page, "S*")
30+
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,26 @@ def get_cell_value(self, column_name: str, row_index: int) -> str:
234234
raise ValueError(
235235
f"No cell found at column '{column_name}' and row index {row_index}"
236236
)
237+
238+
def assert_surname_in_table(self, surname_pattern):
239+
"""
240+
Asserts that a surname matching the given pattern exists in the table.
241+
Args:
242+
surname_pattern (str): The surname or pattern to search for (supports '*' as a wildcard at the end).
243+
"""
244+
# Locate all surname cells (adjust selector as needed)
245+
surname_criteria = self.page.locator(
246+
"//table//tr[position()>1]/td[3]"
247+
) # Use the correct column index
248+
if surname_pattern.endswith("*"):
249+
prefix = surname_pattern[:-1]
250+
found = any(
251+
cell.inner_text().startswith(prefix)
252+
for cell in surname_criteria.element_handles()
253+
)
254+
else:
255+
found = any(
256+
surname_pattern == cell.inner_text()
257+
for cell in surname_criteria.element_handles()
258+
)
259+
assert found, f"No surname matching '{surname_pattern}' found in table."

utils/user_tools.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ 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 get_subject_with_criteria(episode_type, episode_status, has_referral_date, has_diagnosis_date, diagnosis_date_reason):
41+
# Example implementation: fetch NHS number from a test data file based on criteria
42+
test_data_file = Path(os.getcwd()) / "test_subjects.json"
43+
if not test_data_file.exists():
44+
# Fallback to dummy NHS number if file does not exist
45+
return "1234567890"
46+
with open(test_data_file, "r") as file:
47+
subjects = json.load(file)
48+
for subject in subjects:
49+
if (
50+
subject.get("episode_type") == episode_type and
51+
subject.get("episode_status") == episode_status and
52+
subject.get("has_referral_date") == has_referral_date and
53+
subject.get("has_diagnosis_date") == has_diagnosis_date and
54+
subject.get("diagnosis_date_reason") == diagnosis_date_reason
55+
):
56+
return subject.get("nhs_number", "1234567890")
57+
# If no match found, then exception is raised
58+
raise SubjectNotFoundError("No NHS number found using the provided criteria.")
59+
3960
@staticmethod
4061
def retrieve_user(user: str) -> dict:
4162
"""
@@ -59,3 +80,7 @@ def retrieve_user(user: str) -> dict:
5980

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

0 commit comments

Comments
 (0)