Skip to content

Commit f65742f

Browse files
Removing unneeeded method
1 parent 0c4207f commit f65742f

File tree

2 files changed

+4
-264
lines changed

2 files changed

+4
-264
lines changed

pages/datasets/investigation_dataset_page.py

Lines changed: 0 additions & 260 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,266 +1182,6 @@ def get_drug_dosage_text_locator(self, drug_type: str, drug_number: int) -> Loca
11821182
locator_prefix = "#HILITE_spanAntibioticDosageUnit"
11831183
return self.page.locator(f"{locator_prefix}{drug_number}")
11841184

1185-
def does_field_contain_expected_value(
1186-
self,
1187-
dataset_area: str,
1188-
dataset_subsection: str | None,
1189-
field_name: str,
1190-
expected_value: str,
1191-
) -> None:
1192-
"""
1193-
Checks if the specified field contains the expected value in the given dataset area and subsection.
1194-
Args:
1195-
dataset_area (str): The dataset section name.
1196-
dataset_subsection (str | None): The dataset subsection name.
1197-
field_name (str): The field label to check.
1198-
expected_value (str): The expected value to look for.
1199-
"""
1200-
logging.debug(
1201-
f"START: does_field_contain_expected_value({dataset_area}, {dataset_subsection}, {field_name}, {expected_value})"
1202-
)
1203-
map_of_field_and_elements = self.map_fields_and_values(
1204-
dataset_area, dataset_subsection
1205-
)
1206-
actual_value = map_of_field_and_elements.get(field_name.lower())
1207-
if actual_value is not None:
1208-
actual_value = actual_value.replace("\xa0", "").replace(" ", "")
1209-
if actual_value.replace(" ", "") == "":
1210-
actual_value = ""
1211-
if expected_value.lower() not in actual_value.lower():
1212-
raise ValueError(
1213-
f"Value not as expected. Expected: {expected_value}, Actual: '{actual_value}'"
1214-
)
1215-
else:
1216-
raise ValueError(
1217-
f"Field '{field_name}' not found in the dataset area '{dataset_area}' and subsection '{dataset_subsection}'."
1218-
)
1219-
logging.info(
1220-
f"[UI ASSERTIONS COMPLETE] Value as expected. Expected: {expected_value}, Actual: '{actual_value}'"
1221-
)
1222-
logging.debug("END: does_field_contain_expected_value")
1223-
1224-
def map_fields_and_values(
1225-
self, dataset_section: str, dataset_subsection: str | None
1226-
) -> dict[str, str]:
1227-
"""
1228-
Maps field labels to their values for a given dataset section and subsection.
1229-
1230-
Args:
1231-
dataset_section (str): The name of the dataset section.
1232-
dataset_subsection (str | None): The name of the dataset subsection.
1233-
1234-
Returns:
1235-
dict[str, str]: A dictionary mapping field labels to their corresponding values.
1236-
"""
1237-
logging.debug("start: map_fields_and_values()")
1238-
fields_and_elements = self.map_fields_and_elements(
1239-
dataset_section, dataset_subsection
1240-
)
1241-
fields_with_values = {}
1242-
1243-
for field_label, element in fields_and_elements.items():
1244-
fields_with_values[field_label] = self._extract_field_value(element)
1245-
1246-
logging.debug("end: map_fields_and_values()")
1247-
return fields_with_values
1248-
1249-
def _extract_field_value(self, element: Locator) -> str:
1250-
"""
1251-
Extracts the value from a field element, handling different HTML tags.
1252-
1253-
Args:
1254-
element (Locator): The Playwright Locator for the field element.
1255-
1256-
Returns:
1257-
str: The extracted value as a string.
1258-
"""
1259-
value_list = element.locator("xpath=.//*").all()
1260-
if not value_list:
1261-
return element.inner_text()
1262-
field_value = ""
1263-
for value_from_list in value_list:
1264-
tag_name = value_from_list.evaluate("el => el.tagName.toLowerCase()")
1265-
match tag_name:
1266-
case "select":
1267-
selected_option = value_from_list.locator("option:checked")
1268-
field_value += selected_option.inner_text()
1269-
case "li":
1270-
input_elem = value_from_list.locator("input")
1271-
if input_elem.is_checked():
1272-
label_elem = value_from_list.locator("label")
1273-
return label_elem.inner_text()
1274-
case "input":
1275-
input_type = value_from_list.get_attribute("type")
1276-
if input_type == "text":
1277-
field_value += value_from_list.input_value()
1278-
case "p":
1279-
field_value += value_from_list.inner_text()
1280-
case _:
1281-
logging.debug(f"tag type not specified, tag ignored = {tag_name}")
1282-
return field_value
1283-
1284-
def map_fields_and_elements(
1285-
self, dataset_section: str, dataset_subsection: Optional[str] = None
1286-
) -> dict[str, Locator]:
1287-
"""
1288-
Maps field labels to their corresponding Playwright Locator elements for a given dataset section and subsection.
1289-
1290-
Args:
1291-
dataset_section (str): The name of the dataset section.
1292-
dataset_subsection (Optional[str]): The name of the dataset subsection, if any.
1293-
1294-
Returns:
1295-
dict[str, Locator]: A dictionary mapping field labels to their corresponding Locator elements.
1296-
"""
1297-
logging.debug(
1298-
f"start: map_fields_and_elements({dataset_section}, {dataset_subsection})"
1299-
)
1300-
fields_and_elements = {}
1301-
1302-
previous_field = ""
1303-
field_name = ""
1304-
line_counter = 2
1305-
1306-
if dataset_subsection is None:
1307-
section = self.get_dataset_section(dataset_section)
1308-
else:
1309-
section = self.get_dataset_subsection(dataset_section, dataset_subsection)
1310-
1311-
if section is None:
1312-
raise ValueError(
1313-
f"Section '{dataset_section}'{' / ' + dataset_subsection if dataset_subsection else ''} not found."
1314-
)
1315-
1316-
list_of_rows = section.locator(".noTableRow").all()
1317-
self._process_rows_for_field_mapping(
1318-
list_of_rows, fields_and_elements, previous_field, field_name, line_counter
1319-
)
1320-
1321-
logging.debug("end: map_fields_and_elements()")
1322-
return fields_and_elements
1323-
1324-
def _process_rows_for_field_mapping(
1325-
self,
1326-
list_of_rows: list,
1327-
fields_and_elements: dict,
1328-
previous_field: str,
1329-
field_name: str,
1330-
line_counter: int,
1331-
) -> None:
1332-
"""
1333-
Processes each row in the dataset section/subsection and maps field labels to their corresponding Locator elements.
1334-
1335-
Args:
1336-
list_of_rows (list): List of Playwright Locator rows in the section/subsection.
1337-
fields_and_elements (dict): Dictionary to store field label to Locator mappings.
1338-
previous_field (str): The previous field label encountered.
1339-
field_name (str): The current field label being processed.
1340-
line_counter (int): Counter for multi-line fields.
1341-
"""
1342-
for row in list_of_rows:
1343-
elements_in_row = row.locator("xpath=.//*").all()
1344-
field_name, previous_field, element_to_map = (
1345-
self._extract_field_and_element(
1346-
elements_in_row, field_name, previous_field, fields_and_elements
1347-
)
1348-
)
1349-
if element_to_map is None:
1350-
raise ValueError(
1351-
f"Could not find element to map for field '{field_name}'"
1352-
)
1353-
line_counter = self._update_fields_and_elements(
1354-
fields_and_elements,
1355-
field_name,
1356-
previous_field,
1357-
element_to_map,
1358-
line_counter,
1359-
)
1360-
1361-
def _extract_field_and_element(
1362-
self,
1363-
elements_in_row: list,
1364-
field_name: str,
1365-
previous_field: str,
1366-
fields_and_elements: dict,
1367-
) -> tuple[str, str, Optional[Locator]]:
1368-
"""
1369-
Extracts the field name and element to map from the elements in a row.
1370-
1371-
Args:
1372-
elements_in_row (list): List of Playwright Locator elements in the row.
1373-
field_name (str): The current field label being processed.
1374-
previous_field (str): The previous field label encountered.
1375-
fields_and_elements (dict): Dictionary to store field label to Locator mappings.
1376-
1377-
Returns:
1378-
tuple[str, str, Locator]: Updated field_name, previous_field, and element_to_map.
1379-
"""
1380-
element_to_map = None
1381-
for element in elements_in_row:
1382-
element_class = element.get_attribute("class") or ""
1383-
if "label" in element_class:
1384-
previous_field = field_name
1385-
field_name = element.inner_text().lower().replace(" ?", "").strip()
1386-
if field_name in fields_and_elements:
1387-
field_name = self._resolve_field_name_conflict(
1388-
fields_and_elements, field_name
1389-
)
1390-
elif "userInput" in element_class:
1391-
element_to_map = element
1392-
return field_name, previous_field, element_to_map
1393-
1394-
def _resolve_field_name_conflict(
1395-
self, fields_and_elements: dict, field_name: str
1396-
) -> str:
1397-
"""
1398-
Resolves field name conflicts by appending a counter.
1399-
1400-
Args:
1401-
fields_and_elements (dict): Dictionary to store field label to Locator mappings.
1402-
field_name (str): The field name to resolve.
1403-
1404-
Returns:
1405-
str: The resolved field name with a counter appended.
1406-
"""
1407-
name_counter = 2
1408-
while f"{field_name} ({name_counter})" in fields_and_elements:
1409-
name_counter += 1
1410-
return f"{field_name} ({name_counter})"
1411-
1412-
def _update_fields_and_elements(
1413-
self,
1414-
fields_and_elements: dict,
1415-
field_name: str,
1416-
previous_field: str,
1417-
element_to_map: Locator,
1418-
line_counter: int,
1419-
) -> int:
1420-
"""
1421-
Updates the fields_and_elements dictionary with the field name and element, handling multi-line fields.
1422-
1423-
Args:
1424-
fields_and_elements (dict): Dictionary to store field label to Locator mappings.
1425-
field_name (str): The current field label being processed.
1426-
previous_field (str): The previous field label encountered.
1427-
element_to_map (Locator): The element to map.
1428-
line_counter (int): Counter for multi-line fields.
1429-
1430-
Returns:
1431-
int: The updated line_counter value.
1432-
"""
1433-
if field_name.replace(" ", "") != "":
1434-
fields_and_elements[field_name] = element_to_map
1435-
return 2
1436-
if (
1437-
hasattr(self, "list_of_multi_line_fields")
1438-
and previous_field in self.list_of_multi_line_fields
1439-
):
1440-
field_name = previous_field
1441-
fields_and_elements[f"{field_name} ({line_counter})"] = element_to_map
1442-
return line_counter + 1
1443-
return line_counter
1444-
14451185
def assert_test_result(self, expected_text: str) -> None:
14461186
"""
14471187
Asserts that the text in the test result matches the expected text.

tests/regression/regression_tests/surveillance_regression_tests/test_surveillance_scenario_10.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def test_scenario_10(page: Page, general_properties: dict) -> None:
244244
)
245245

246246
# Then I confirm the "Investigation Dataset" section of the dataset contains the field "Actual Type of Test" with the value of "Flexible Sigmoidoscopy"
247-
InvestigationDatasetsPage(page).does_field_contain_expected_value(
248-
"Investigation Dataset", None, "Actual Type of Test", "Flexible Sigmoidoscopy"
247+
DatasetFieldUtil(page).assert_cell_to_right_has_expected_text(
248+
"Actual Type of Test", "Flexible Sigmoidoscopy"
249249
)
250250

251251
# Then I get a confirmation prompt that "contains" "Are you sure you want to change the actual type of diagnostic test to Colonoscopy?"
@@ -262,8 +262,8 @@ def test_scenario_10(page: Page, general_properties: dict) -> None:
262262
)
263263

264264
# Then I confirm the "Investigation Dataset" section of the dataset contains the field "Actual Type of Test" with the value of "Colonoscopy"
265-
InvestigationDatasetsPage(page).does_field_contain_expected_value(
266-
"Investigation Dataset", None, "Actual Type of Test", "Colonoscopy"
265+
DatasetFieldUtil(page).assert_cell_to_right_has_expected_text(
266+
"Actual Type of Test", "Colonoscopy"
267267
)
268268

269269
# When I add the following bowel preparation drugs and values within the Investigation Dataset for this subject:

0 commit comments

Comments
 (0)