Skip to content

Commit e11670e

Browse files
Addressing SonarQube comments
1 parent a080115 commit e11670e

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

pages/datasets/investigation_dataset_page.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

13441361
def normalize_label(text: str) -> str:
13451362
"""

pages/screening_subject_search/handover_into_symptomatic_care_page.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, page: Page):
2626
self.mdt_date_field = self.page.locator("#UI_MDT_DATE")
2727
self.site_dropdown = self.page.locator("#UI_NS_SITE_SELECT_LINK")
2828
self.date_responsibility_accepted_field = self.page.locator("#UI_OTHER_DATE")
29+
self.select_locator = self.page.locator('select[id^="UI_RESULTS_"]:visible')
2930

3031
def select_referral_dropdown_option(self, value: str) -> None:
3132
"""
@@ -51,11 +52,10 @@ def select_non_screening_practitioner_link(self, practitioner_index: int) -> Non
5152
practitioner_index (int): The index of the non screening practitioner to select.
5253
"""
5354
self.non_screening_practitioner_link.click()
54-
select_locator = self.page.locator('select[id^="UI_RESULTS_"]:visible')
55-
select_locator.first.wait_for(state="visible")
55+
self.select_locator.first.wait_for(state="visible")
5656

5757
# Find all option elements inside the select and click the one at the given index
58-
option_elements = select_locator.first.locator("option")
58+
option_elements = self.select_locator.first.locator("option")
5959
option_elements.nth(practitioner_index).wait_for(state="visible")
6060
self.click(option_elements.nth(practitioner_index))
6161

@@ -82,11 +82,10 @@ def select_consultant_from_index(self, consultant_index: int) -> None:
8282
consultant_index (int): The index of the consultant to select.
8383
"""
8484
self.click(self.consultant_link)
85-
select_locator = self.page.locator('select[id^="UI_RESULTS_"]:visible')
86-
select_locator.first.wait_for(state="visible")
85+
self.select_locator.first.wait_for(state="visible")
8786

8887
# Find all option elements inside the select and click the one at the given index
89-
option_elements = select_locator.first.locator("option")
88+
option_elements = self.select_locator.first.locator("option")
9089
option_elements.nth(consultant_index).wait_for(state="visible")
9190
self.click(option_elements.nth(consultant_index))
9291

@@ -140,11 +139,10 @@ def select_site_dropdown_option_index(self, index: int) -> None:
140139
value (str): The value of the option you want to select
141140
"""
142141
self.click(self.site_dropdown)
143-
select_locator = self.page.locator('select[id^="UI_RESULTS_"]:visible')
144-
select_locator.first.wait_for(state="visible")
142+
self.select_locator.first.wait_for(state="visible")
145143

146144
# Find all option elements inside the select and click the one at the given index
147-
option_elements = select_locator.first.locator("option")
145+
option_elements = self.select_locator.first.locator("option")
148146
option_elements.nth(index).wait_for(state="visible")
149147
self.click(option_elements.nth(index))
150148

tests/regression/regression_tests/surveillance_regression_tests/test_surveillance_scenario_10.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def test_scenario_10(page: Page, general_properties: dict) -> None:
373373
)
374374

375375
# Then the Investigation Dataset result message is "High-risk findings"
376-
InvestigationDatasetsPage(page).expect_text_to_be_visible("High-risk findings")
376+
InvestigationDatasetsPage(page).assert_test_result("High-risk findings")
377377

378378
# Then I confirm the Polyp Algorithm Size for Polyp 1 is 10
379379
InvestigationDatasetsPage(page).assert_polyp_algorithm_size(1, "10")

0 commit comments

Comments
 (0)