22from playwright .sync_api import Page , Locator
33from pages .base_page import BasePage
44from typing import Dict
5-
6- # Assume you have a CalendarPicker utility in your project
75from utils .calendar_picker import CalendarPicker
86
97class SpineSearchPage :
@@ -13,38 +11,28 @@ class SpineSearchPage:
1311 """
1412 def __init__ (self , page : Page ):
1513 self .page = page
16- self .spine_url = "https://bcss-bcss-18680-ddc-bcss.k8s-nonprod.texasplatform.uk/servlet/SpineSearchScreen"
1714
1815 # Define locators
19- self .retrieve_data_link = self .page .get_by_role ("link" , name = "Retrieve Data from Spine" )
2016 self .demographics_radio = self .page .get_by_role ("radio" , name = "Demographics" )
2117 self .date_of_birth_field = self .page .locator ("#dateOfBirth" )
2218 self .surname_field = self .page .locator ("#surname" )
2319 self .forename_field = self .page .locator ("#forename" )
2420 self .gender_dropdown = self .page .locator ("#gender" )
2521 self .postcode_field = self .page .locator ("#postcode" )
2622 self .search_button = self .page .get_by_role ("button" , name = "Search" )
27- self .alert_message = self .page .locator (".spine-alert" )
23+ self .alert_locator = self .page .locator (".spine-alert" )
2824
2925 # CalendarPicker utility instance
3026 self .calendar_picker = CalendarPicker (self .page )
3127
32- def navigate_to_spine_search (self ) -> None :
33- """
34- Navigates to the Spine Search screen by clicking the appropriate link
35- and loading the target URL.
36- """
37- self .retrieve_data_link .click ()
38- self .page .goto (self .spine_url )
39-
4028 def select_demographic_search (self ) -> None :
4129 """
4230 Selects the 'Demographics' radio button to enable demographic search mode.
4331 """
4432 self .demographics_radio .check ()
4533
4634 def enter_search_criteria (
47- self , dob : str , surname : str , forename : str , gender : str , postcode : str
35+ self , dob : str , surname : str , forename : str , gender : str , postcode : str
4836) -> None :
4937 """
5038 Fills in the demographic search fields with the provided values.
@@ -59,7 +47,7 @@ def enter_search_criteria(
5947
6048 # Convert dob string to datetime object
6149 dob_dt = datetime .strptime (dob , "%d %b %Y" ) # Adjust format if needed
62- self .date_of_birth_field . click ()
50+ self .click (self . date_of_birth_field )
6351 self .calendar_picker .v2_calendar_picker (dob_dt ) # dob should be in a supported format, e.g. "YYYY-MM-DD"
6452 self .surname_field .fill (surname )
6553 self .forename_field .fill (forename )
@@ -71,10 +59,33 @@ def perform_search(self) -> None:
7159 """
7260 Clicks the 'Search' button to initiate the Spine demographic search.
7361 """
74- self .search_button .click ()
62+ self .click (self .search_button )
63+
64+ def click (self , locator : Locator ) -> None :
65+ """
66+ Clicks on the specified locator.
67+
68+ Args:
69+ locator (Locator): The Playwright locator to click.
70+ """
71+ try :
72+ locator .click ()
73+ except Exception as e :
74+ print (f"Error clicking on locator: { e } " )
7575
7676 def get_spine_alert_message (self ) -> str :
77- alert_locator = self .page .locator (".spine-alert" ) # Update selector if needed
77+ """
78+ Retrieves the text content of a visible spine alert message from the page.
79+
80+ This method waits for the alert element with the CSS class `.spine-alert` to become visible
81+ within a 5-second timeout. If the alert appears, its inner text is returned after stripping
82+ leading and trailing whitespace. If the alert does not appear within the timeout or an unexpected
83+ error occurs, an empty string is returned and the error is logged to the console.
84+
85+ Returns:
86+ str: The stripped text of the alert message if visible, otherwise an empty string.
87+ """
88+ alert_locator = self .page .locator (".spine-alert" )
7889 try :
7990 alert_locator .wait_for (state = "visible" , timeout = 5000 )
8091 return alert_locator .inner_text ().strip ()
0 commit comments