Skip to content

Commit c07e405

Browse files
Refacoring util to work for surveillance regression tests
1 parent 2a2a265 commit c07e405

File tree

3 files changed

+148
-90
lines changed

3 files changed

+148
-90
lines changed

pages/datasets/investigation_dataset_page.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(self, page: Page):
9696
self.diagnostic_test_result = self.page.locator(
9797
"#datasetContent > div:nth-child(1) > div:nth-child(7) > span.userInput"
9898
)
99+
self.show_details_links = self.page.locator('a:has-text("Show details")')
99100

100101
# Repeat strings:
101102
self.bowel_preparation_administered_string = "Bowel Preparation Administered"
@@ -361,10 +362,13 @@ def select_diagnostic_procedure_type(self) -> None:
361362

362363
def click_show_completion_proof_information(self) -> None:
363364
"""
364-
This method is designed to click on the show completion proof information link.
365-
It clicks on the show completion proof information link.
365+
Clicks on the show completion proof information link if it contains the text "show" (case-insensitive).
366366
"""
367-
self.click(self.show_completion_proof_information_details)
367+
if (
368+
"show"
369+
in self.show_completion_proof_information_details.inner_text().lower()
370+
):
371+
self.click(self.show_completion_proof_information_details)
368372

369373
def click_show_failure_information(self) -> None:
370374
"""
@@ -416,6 +420,16 @@ def click_save_dataset_button(self) -> None:
416420
"""
417421
self.safe_accept_dialog(self.save_dataset_button)
418422

423+
def click_save_dataset_button_assert_dialog(self, expected_text: str) -> None:
424+
"""
425+
Clicks on the save dataset button and performs an assertion of the resulting dialog text.
426+
Once done dismissed the dialog.
427+
Args:
428+
expected_text (str): The expected text in the resultant dialog
429+
"""
430+
self.assert_dialog_text("High-risk findings")
431+
self.click(self.save_dataset_button)
432+
419433
def expect_text_to_be_visible(self, text: str) -> None:
420434
"""
421435
This method is designed to expect a text to be visible on the page.
@@ -1193,6 +1207,24 @@ def assert_test_result(self, expected_text: str) -> None:
11931207
actual_text.lower() == expected_text.lower()
11941208
), f"Expected '{expected_text}', but found '{actual_text}'"
11951209

1210+
def open_all_details_tabs(self) -> None:
1211+
"""
1212+
Clicks all visible "Show details" links on the page to open all details tabs.
1213+
"""
1214+
count = self.show_details_links.count()
1215+
for i in range(count):
1216+
link = self.show_details_links.nth(i)
1217+
if link.is_visible():
1218+
self.click(link)
1219+
1220+
def open_all_minimized_sections(self) -> None:
1221+
"""
1222+
Opens all the minimized sections in the investigation dataset form.
1223+
"""
1224+
self.open_all_details_tabs()
1225+
# Then do it again to get the internal sections
1226+
self.open_all_details_tabs()
1227+
11961228

11971229
def normalize_label(text: str) -> str:
11981230
"""

tests/regression/regression_tests/surveillance_regression_tests/test_surveillance_scenario_10.py

Lines changed: 83 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ def test_scenario_10(page: Page, general_properties: dict) -> None:
243243
"Investigation Datasets"
244244
)
245245

246+
# And I open all minimized sections on the dataset
247+
InvestigationDatasetsPage(page).open_all_minimized_sections()
248+
246249
# Then I confirm the "Investigation Dataset" section of the dataset contains the field "Actual Type of Test" with the value of "Flexible Sigmoidoscopy"
247250
DatasetFieldUtil(page).assert_cell_to_right_has_expected_text(
248251
"Actual Type of Test", "Flexible Sigmoidoscopy"
@@ -256,7 +259,6 @@ def test_scenario_10(page: Page, general_properties: dict) -> None:
256259
)
257260

258261
# When I set the following fields and values within the Investigation Dataset for this subject:
259-
InvestigationDatasetsPage(page).click_show_endoscopy_information()
260262
DatasetFieldUtil(page).populate_select_locator_for_field(
261263
"Endoscopist defined extent", EndoscopyLocationOptions.APPENDIX
262264
)
@@ -267,10 +269,12 @@ def test_scenario_10(page: Page, general_properties: dict) -> None:
267269
)
268270

269271
# When I add the following bowel preparation drugs and values within the Investigation Dataset for this subject:
270-
drug_information = {
271-
"drug_dose1": "3",
272-
"drug_type1": DrugTypeOptions.MANNITOL,
273-
}
272+
InvestigationDatasetCompletion(page).fill_out_drug_information(
273+
{
274+
"drug_dose1": "3",
275+
"drug_type1": DrugTypeOptions.MANNITOL,
276+
}
277+
)
274278

275279
# And there is a clinician who meets the following criteria:
276280
user = User.from_user_role_type(user_role)
@@ -288,92 +292,104 @@ def test_scenario_10(page: Page, general_properties: dict) -> None:
288292
)
289293

290294
# And I set the following fields and values within the Investigation Dataset for this subject:
291-
general_information = {
292-
"practitioner": 1,
293-
"site": 1,
294-
"testing clinician": person_name,
295-
"aspirant endoscopist": None,
296-
}
295+
InvestigationDatasetCompletion(page).fill_out_general_information(
296+
{
297+
"practitioner": 1,
298+
"site": 1,
299+
"testing clinician": person_name,
300+
"aspirant endoscopist": None,
301+
}
302+
)
297303

298-
endoscopy_information = {
299-
"endoscope inserted": "yes",
300-
"procedure type": "therapeutic",
301-
"bowel preparation quality": BowelPreparationQualityOptions.GOOD,
302-
"comfort during recovery": ComfortOptions.NO_DISCOMFORT,
303-
"comfort during examination": ComfortOptions.NO_DISCOMFORT,
304-
"scope imager used": YesNoOptions.YES,
305-
"retroverted view": YesNoOptions.NO,
306-
"start of intubation time": "09:00",
307-
"start of extubation time": "09:30",
308-
"end time of procedure": "10:00",
309-
"scope id": "Autotest",
310-
"insufflation": InsufflationOptions.AIR,
311-
"outcome at time of procedure": OutcomeAtTimeOfProcedureOptions.LEAVE_DEPARTMENT,
312-
"late outcome": LateOutcomeOptions.NO_COMPLICATIONS,
313-
}
304+
InvestigationDatasetCompletion(page).fill_endoscopy_information(
305+
{
306+
"endoscope inserted": "yes",
307+
"procedure type": "therapeutic",
308+
"bowel preparation quality": BowelPreparationQualityOptions.GOOD,
309+
"comfort during recovery": ComfortOptions.NO_DISCOMFORT,
310+
"comfort during examination": ComfortOptions.NO_DISCOMFORT,
311+
"scope imager used": YesNoOptions.YES,
312+
"retroverted view": YesNoOptions.NO,
313+
"start of intubation time": "09:00",
314+
"start of extubation time": "09:30",
315+
"end time of procedure": "10:00",
316+
"scope id": "Autotest",
317+
"insufflation": InsufflationOptions.AIR,
318+
"outcome at time of procedure": OutcomeAtTimeOfProcedureOptions.LEAVE_DEPARTMENT,
319+
"late outcome": LateOutcomeOptions.NO_COMPLICATIONS,
320+
}
321+
)
314322

315323
# And I set the following completion proof values within the Investigation Dataset for this subject:
316-
completion_information = {"completion proof": CompletionProofOptions.VIDEO_APPENDIX}
324+
InvestigationDatasetCompletion(page).fill_out_completion_information(
325+
{"completion proof": CompletionProofOptions.VIDEO_APPENDIX}
326+
)
317327

318328
# And I set the following failure reasons within the Investigation Dataset for this subject:
319-
failure_information = {"failure reasons": FailureReasonsOptions.NO_FAILURE_REASONS}
329+
InvestigationDatasetCompletion(page).fill_out_failure_information(
330+
{"failure reasons": FailureReasonsOptions.NO_FAILURE_REASONS}
331+
)
320332

321-
# And I add new polyps 1-2 with the following fields and values within the Investigation Dataset for this subject:
322-
polyp_information = [
333+
# And I add new polyp 1 with the following fields and values within the Investigation Dataset for this subject:
334+
InvestigationDatasetCompletion(page).fill_polyp_x_information(
323335
{
324336
"location": EndoscopyLocationOptions.CAECUM,
325337
"classification": PolypClassificationOptions.LST_NG,
326338
"estimate of whole polyp size": "10",
327339
"polyp access": PolypAccessOptions.EASY,
328340
"left in situ": YesNoOptions.NO,
329341
},
342+
1,
343+
)
344+
345+
# And I add intervention 1 for polyp 1 with the following fields and values within the Investigation Dataset for this subject:
346+
InvestigationDatasetCompletion(page).fill_polyp_x_intervention(
347+
{
348+
"modality": PolypInterventionModalityOptions.EMR,
349+
"device": PolypInterventionDeviceOptions.HOT_SNARE,
350+
"excised": YesNoOptions.YES,
351+
"retrieved": PolypInterventionRetrievedOptions.NO,
352+
"excision technique": PolypInterventionExcisionTechniqueOptions.EN_BLOC,
353+
},
354+
1,
355+
)
356+
357+
# And I add new polyp 2 with the following fields and values within the Investigation Dataset for this subject:
358+
InvestigationDatasetCompletion(page).fill_polyp_x_information(
330359
{
331360
"location": EndoscopyLocationOptions.ASCENDING_COLON,
332361
"classification": PolypClassificationOptions.IIA,
333362
"estimate of whole polyp size": "12",
334363
"polyp access": PolypAccessOptions.EASY,
335364
"left in situ": YesNoOptions.NO,
336365
},
337-
]
366+
2,
367+
)
338368

339-
# And I add intervention 1 for polyps 1-2 with the following fields and values within the Investigation Dataset for this subject:
340-
polyp_intervention = [
341-
[
342-
{
343-
"modality": PolypInterventionModalityOptions.EMR,
344-
"device": PolypInterventionDeviceOptions.HOT_SNARE,
345-
"excised": YesNoOptions.YES,
346-
"retrieved": PolypInterventionRetrievedOptions.NO,
347-
"excision technique": PolypInterventionExcisionTechniqueOptions.EN_BLOC,
348-
}
349-
],
350-
[
351-
{
352-
"modality": PolypInterventionModalityOptions.POLYPECTOMY,
353-
"device": PolypInterventionDeviceOptions.HOT_SNARE,
354-
"excised": YesNoOptions.YES,
355-
"retrieved": PolypInterventionRetrievedOptions.NO,
356-
"excision technique": PolypInterventionExcisionTechniqueOptions.PIECE_MEAL,
357-
"polyp appears fully resected endoscopically": YesNoUncertainOptions.UNCERTAIN,
358-
}
359-
],
360-
]
369+
# And I add intervention 1 for polyp 2 with the following fields and values within the Investigation Dataset for this subject:
370+
InvestigationDatasetCompletion(page).fill_polyp_x_intervention(
371+
{
372+
"modality": PolypInterventionModalityOptions.POLYPECTOMY,
373+
"device": PolypInterventionDeviceOptions.HOT_SNARE,
374+
"excised": YesNoOptions.YES,
375+
"retrieved": PolypInterventionRetrievedOptions.NO,
376+
"excision technique": PolypInterventionExcisionTechniqueOptions.PIECE_MEAL,
377+
"polyp appears fully resected endoscopically": YesNoUncertainOptions.UNCERTAIN,
378+
},
379+
2,
380+
)
361381

362382
# And I mark the Investigation Dataset as completed
383+
InvestigationDatasetsPage(page).check_dataset_complete_checkbox()
384+
385+
# When I press the save Investigation Dataset button
386+
# Then the Investigation Dataset result message, which I will cancel, is "High-risk findings"
387+
InvestigationDatasetsPage(page).click_save_dataset_button_assert_dialog(
388+
"High-risk findings"
389+
)
390+
363391
# When I press the save Investigation Dataset button
364-
InvestigationDatasetsPage(page).click_show_endoscopy_information()
365-
InvestigationDatasetCompletion(page).complete_dataset_with_args(
366-
endoscopy_information=endoscopy_information,
367-
drug_information=drug_information,
368-
general_information=general_information,
369-
failure_information=failure_information,
370-
completion_information=completion_information,
371-
polyp_information=polyp_information,
372-
polyp_intervention=polyp_intervention,
373-
)
374-
375-
# Then the Investigation Dataset result message is "High-risk findings"
376-
InvestigationDatasetsPage(page).assert_test_result("High-risk findings")
392+
InvestigationDatasetsPage(page).click_save_dataset_button()
377393

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

utils/investigation_dataset.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ def complete_dataset_with_args(
363363

364364
# Drug Information
365365
if drug_information is not None:
366-
InvestigationDatasetsPage(self.page).click_show_drug_information()
367366
self.fill_out_drug_information(drug_information)
368367

369368
if endoscopy_information:
@@ -373,17 +372,13 @@ def complete_dataset_with_args(
373372
# Completion Proof Information
374373
if completion_information is not None:
375374
logging.info("Filling out completion proof information")
376-
InvestigationDatasetsPage(
377-
self.page
378-
).click_show_completion_proof_information()
379375
DatasetFieldUtil(self.page).populate_select_locator_for_field(
380376
"Proof Parameters", completion_information["completion proof"]
381377
)
382378

383379
# Failure Information
384380
if failure_information is not None:
385381
logging.info("Filling out failure information")
386-
self.investigation_datasets_pom.click_show_failure_information()
387382
DatasetFieldUtil(self.page).populate_select_locator_for_field_inside_div(
388383
self.failure_reasons_string,
389384
"divFailureSection",
@@ -424,14 +419,6 @@ def fill_out_suspected_findings(self, suspected_findings: dict) -> None:
424419
"""
425420
Populates the Suspected Findings section of the Investigation Dataset form.
426421
"""
427-
logging.info("Starting fill_out_suspected_findings")
428-
try:
429-
logging.info("About to click suspected findings details")
430-
self.investigation_datasets_pom.click_show_suspected_findings_details()
431-
logging.info("Clicked suspected findings details successfully")
432-
except Exception as e:
433-
logging.error(f"Error clicking on Show Suspected Findings Details: {e}")
434-
raise
435422
for key, value in suspected_findings.items():
436423
match key:
437424
case "extracolonic summary code":
@@ -500,12 +487,40 @@ def fill_out_general_information(self, general_information: dict) -> None:
500487
self.page
501488
).select_aspirant_endoscopist_option_index(aspirant)
502489

490+
def fill_out_completion_information(self, completion_information: dict) -> None:
491+
"""
492+
This method completes the Completion Proof Information section of the investigation dataset.
493+
Args:
494+
completion_information (dict): A dictionary containing completion proof parameters.
495+
"""
496+
logging.info("Filling out completion proof information")
497+
self.investigation_datasets_pom.click_show_completion_proof_information()
498+
DatasetFieldUtil(self.page).populate_select_locator_for_field(
499+
"Proof Parameters", completion_information["completion proof"]
500+
)
501+
502+
def fill_out_failure_information(self, failure_information: dict) -> None:
503+
"""
504+
This method completes the Failure Information section of the investigation dataset.
505+
Args:
506+
failure_information (dict): A dictionary containing failure reasons and related information.
507+
"""
508+
logging.info("Filling out failure information")
509+
DatasetFieldUtil(self.page).populate_select_locator_for_field_inside_div(
510+
self.failure_reasons_string,
511+
"divFailureSection",
512+
failure_information["failure reasons"],
513+
)
514+
503515
def fill_out_contrast_tagging_and_drug_information(
504516
self, contrast_tagging_and_drug: dict
505517
) -> None:
518+
"""
519+
This method completes the Contrast, Tagging & Drug Information section of the investigation dataset.
520+
Args:
521+
contrast_tagging_and_drug (dict): A dictionary containing contrast, tagging agent, and drug information.
522+
"""
506523
logging.info("🧪 Filling out Contrast, Tagging & Drug Information")
507-
self.investigation_datasets_pom.click_show_contrast_tagging_and_drug_information()
508-
509524
# Use for loop and match-case for endoscopy_information fields
510525
for key, value in contrast_tagging_and_drug.items():
511526
match key:
@@ -635,9 +650,6 @@ def fill_out_radiology_information(self, radiology_data: dict) -> None:
635650
"""
636651
logging.info("Filling out Radiology Information")
637652

638-
self.investigation_datasets_pom.click_show_radiology_information()
639-
self.investigation_datasets_pom.click_show_radiology_failure_information()
640-
641653
# Use for loop and match-case for radiology data fields
642654
for key, value in radiology_data.items():
643655
match key:
@@ -722,8 +734,6 @@ def fill_endoscopy_information(self, endoscopy_information: dict) -> None:
722734
endoscopy_information (dict): A dictionary containing the endoscopy information to be filled in the form.
723735
"""
724736
# Endoscopy Information
725-
self.investigation_datasets_pom.click_show_endoscopy_information()
726-
727737
# Use for loop and match-case for endoscopy_information fields
728738
for key, value in endoscopy_information.items():
729739
match key:

0 commit comments

Comments
 (0)