@@ -93,6 +93,7 @@ def __init__(self, page: Page):
9393 self .visible_search_text_input = self .page .locator (
9494 'input[id^="UI_SEARCH_"]:visible'
9595 )
96+ self .diagnostic_test_result = self .page .locator ('#datasetContent > div:nth-child(1) > div:nth-child(7) > span.userInput' )
9697
9798 # Repeat strings:
9899 self .bowel_preparation_administered_string = "Bowel Preparation Administered"
@@ -1221,6 +1222,10 @@ def does_field_contain_expected_value(
12211222 logging .info (
12221223 f"[UI ASSERTIONS COMPLETE] Value as expected. Expected: { expected_value } , Actual: '{ actual_value } '"
12231224 )
1225+ else :
1226+ raise ValueError (
1227+ f"[UI ASSERTIONS FAILED] Field '{ field_name } ' with expected value '{ expected_value } ' not found."
1228+ )
12241229
12251230 def map_fields_and_values (
12261231 self , dataset_section : str , dataset_subsection : str | None
@@ -1250,25 +1255,26 @@ def map_fields_and_values(
12501255 tag_name = value_from_list .evaluate (
12511256 "el => el.tagName.toLowerCase()"
12521257 )
1253- if tag_name == "select" :
1254- # Get selected option text
1255- selected_option = value_from_list .locator ("option:checked" )
1256- field_value += selected_option .inner_text ()
1257- elif tag_name == "li" :
1258- input_elem = value_from_list .locator ("input" )
1259- if input_elem .is_checked ():
1260- label_elem = value_from_list .locator ("label" )
1261- field_value = label_elem .inner_text ()
1262- elif tag_name == "input" :
1263- input_type = value_from_list .get_attribute ("type" )
1264- if input_type == "text" :
1265- field_value += value_from_list .input_value ()
1266- elif tag_name == "p" :
1267- field_value += value_from_list .inner_text ()
1268- else :
1269- logging .debug (
1270- f"tag type not specified, tag ignored = { tag_name } "
1271- )
1258+ match tag_name :
1259+ case "select" :
1260+ # Get selected option text
1261+ selected_option = value_from_list .locator ("option:checked" )
1262+ field_value += selected_option .inner_text ()
1263+ case "li" :
1264+ input_elem = value_from_list .locator ("input" )
1265+ if input_elem .is_checked ():
1266+ label_elem = value_from_list .locator ("label" )
1267+ field_value = label_elem .inner_text ()
1268+ case "input" :
1269+ input_type = value_from_list .get_attribute ("type" )
1270+ if input_type == "text" :
1271+ field_value += value_from_list .input_value ()
1272+ case "p" :
1273+ field_value += value_from_list .inner_text ()
1274+ case _:
1275+ logging .debug (
1276+ f"tag type not specified, tag ignored = { tag_name } "
1277+ )
12721278 fields_with_values [field_label ] = field_value
12731279
12741280 logging .debug ("end: map_fields_and_values()" )
@@ -1340,6 +1346,17 @@ def map_fields_and_elements(
13401346 logging .debug ("end: map_fields_and_elements()" )
13411347 return fields_and_elements
13421348
1349+ def assert_test_result (self , expected_text : str ) -> None :
1350+ """
1351+ Asserts that the text in the test result matches the expected text.
1352+ Args:
1353+ expected_text (str): The text expected to be found in the element.
1354+ """
1355+ actual_text = self .diagnostic_test_result .inner_text ().strip ()
1356+ assert (
1357+ actual_text .lower () == expected_text .lower ()
1358+ ), f"Expected '{ expected_text } ', but found '{ actual_text } '"
1359+
13431360
13441361def normalize_label (text : str ) -> str :
13451362 """
0 commit comments