Skip to content

Commit 89f15ac

Browse files
Code Refactoring is Implemented for JIRA Ticket - https://nhsd-jira.digital.nhs.uk/browse/BCSS-20611 - Selenium to Playwright - Regression Tests - Subject - Subject Search
1 parent 4e12559 commit 89f15ac

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
from playwright.sync_api import Page, expect
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+
8+
@pytest.mark.regression
9+
@pytest.mark.subject_search
10+
def test_user_can_search_for_subject_and_results_are_returned(page: Page):
11+
"""
12+
Verify that User can log in to BCSS "England" as user role "Hub Manager - State Registered"
13+
Navigate it to the Subject Search Criteria Page & added value "S*" to the "Surname" search field
14+
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
16+
"""
17+
18+
# Log in as Hub Manager - State Registered (England)
19+
UserTools.user_login(page, "Hub Manager State Registered at BCS01")
20+
21+
# Navigate to the Subject Search Criteria Page
22+
BasePage(page).go_to_screening_subject_search_page()
23+
24+
# Add value "S*" to the "Surname" search field
25+
# click search button on the subject search criteria page
26+
search_subject_by_surname(page, "S*")
27+
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+

utils/table_util.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,19 @@ 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+
242+
Args:
243+
surname_pattern (str): The surname or pattern to search for (supports '*' as a wildcard at the end).
244+
"""
245+
# 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
247+
if surname_pattern.endswith("*"):
248+
prefix = surname_pattern[:-1]
249+
found = any(cell.inner_text().startswith(prefix) for cell in surname_criteria.element_handles())
250+
else:
251+
found = any(surname_pattern == cell.inner_text() for cell in surname_criteria.element_handles())
252+
assert found, f"No surname matching '{surname_pattern}' found in table."

utils/user_tools.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,32 @@ 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+
44+
@staticmethod
45+
def get_subject_with_criteria(episode_type, episode_status, has_referral_date, has_diagnosis_date, diagnosis_date_reason):
46+
# Example implementation: fetch NHS number from a test data file based on criteria
47+
test_data_file = Path(os.getcwd()) / "test_subjects.json"
48+
if not test_data_file.exists():
49+
# Fallback to dummy NHS number if file does not exist
50+
return "1234567890"
51+
with open(test_data_file, "r") as file:
52+
subjects = json.load(file)
53+
for subject in subjects:
54+
if (
55+
subject.get("episode_type") == episode_type and
56+
subject.get("episode_status") == episode_status and
57+
subject.get("has_referral_date") == has_referral_date and
58+
subject.get("has_diagnosis_date") == has_diagnosis_date and
59+
subject.get("diagnosis_date_reason") == diagnosis_date_reason
60+
):
61+
return subject.get("nhs_number", "1234567890")
62+
# If no match found, return dummy NHS number
63+
return "1234567890"
64+
3965
@staticmethod
4066
def retrieve_user(user: str) -> dict:
4167
"""

0 commit comments

Comments
 (0)