1+ import re
12from playwright .sync_api import Page , expect , Locator
23from pages .base_page import BasePage
34from enum import StrEnum
78)
89from typing import Optional
910import logging
10- import re
1111
1212
1313class InvestigationDatasetsPage (BasePage ):
@@ -354,7 +354,6 @@ def select_polyp1_pathologist_option_index(self, option: int) -> None:
354354 """
355355 This method is designed to select a pathologist from the pathologist options.
356356 It clicks on the pathologist link and selects the given option by index.
357-
358357 Args:
359358 option (int): The index of the option to select from the pathologist options.
360359 """
@@ -370,7 +369,6 @@ def select_lookup_option_index(self, option: int) -> None:
370369 """
371370 This method is designed to select a lookup option by index.
372371 It clicks on the lookup link and selects the given option by index.
373-
374372 Args:
375373 option (int): The index of the option to select from the lookup options.
376374 """
@@ -394,7 +392,6 @@ def assert_polyp_algorithm_size(
394392 """
395393 This method asserts that the polyp size is as expected.
396394 It retrieves the polyp size from the page and compares it with the expected value.
397-
398395 Args:
399396 polyp_number (int): The number of the polyp to check (1 or 2).
400397 expected_value (int): The expected value of the polyp size.
@@ -426,7 +423,6 @@ def assert_polyp_category(
426423 """
427424 This method asserts that the polyp category is as expected.
428425 It retrieves the polyp category from the page and compares it with the expected value.
429-
430426 Args:
431427 polyp_number (int): The number of the polyp to check (1 or 2).
432428 expected_value (str): The expected value of the polyp category.
@@ -474,7 +470,6 @@ def get_dataset_id(self) -> int:
474470 def click_polyp_add_intervention_button (self , polyp_number : int ) -> None :
475471 """
476472 Clicks the add intervention button for the specified polyp number.
477-
478473 Args:
479474 polyp_number (int): The number of the polyp.
480475 """
@@ -490,15 +485,12 @@ def populate_select_by_id(
490485 ) -> None :
491486 """
492487 Populates a <select> element using a predictable ID pattern based on field name and polyp number.
493-
494488 This method is useful when label-based selectors (e.g., using `right-of(:text(...))`) are unreliable
495489 due to ambiguous or repeated text labels on the page.
496-
497490 Args:
498491 field_base (str): The base name of the field (e.g., "POLYP_PATHOLOGY_LOST").
499492 polyp_number (int): The polyp index (e.g., 1 for the first polyp).
500493 option (str): The value to be selected from the dropdown.
501-
502494 Example:
503495 populate_select_by_id("POLYP_PATHOLOGY_LOST", 1, YesNoOptions.YES)
504496 # Selects 'Yes' in <select id="UI_POLYP_PATHOLOGY_LOST1_1">
@@ -519,14 +511,12 @@ def is_edit_dataset_button_visible(self) -> bool:
519511 def is_dataset_section_present (self , dataset_section_name : str ) -> bool | None :
520512 """
521513 Checks if a section of the investigation dataset is present
522-
523514 Args:
524515 dataset_section_name (str): The name of the section you want to check
525516 - Investigation Dataset
526517 - Drug Information
527518 - Endoscopy Information
528519 - etc...
529-
530520 Returns:
531521 bool: True if it is present, False if it is not
532522 """
@@ -550,13 +540,10 @@ def is_dataset_section_present(self, dataset_section_name: str) -> bool | None:
550540 def get_dataset_section (self , dataset_section_name : str ) -> Locator | None :
551541 """
552542 Retrieves a dataset section by matching its header text.
553-
554543 Searches through all elements representing dataset sections, looking for one whose
555544 first <h4> header text matches the provided section name (case-insensitive).
556-
557545 Args:
558546 dataset_section_name (str): The name of the dataset section to locate.
559-
560547 Returns:
561548 Locator | None: A Playwright Locator for the matching section, or None if not found.
562549 """
@@ -583,17 +570,13 @@ def get_dataset_subsection(
583570 ) -> Locator | None :
584571 """
585572 Retrieves a specific subsection within a dataset section by matching the subsection's header text.
586-
587573 The method first searches through elements with the `.DatasetSubSection` class.
588574 If the subsection is not found, it continues searching within `.DatasetSubSectionGroup` elements.
589-
590575 Args:
591576 dataset_section_name (str): The name of the dataset section that contains the subsection.
592577 dataset_subsection_name (str): The name of the subsection to locate.
593-
594578 Returns:
595579 Locator | None: A Playwright Locator for the found subsection, or None if not found.
596-
597580 Raises:
598581 ValueError: If the specified dataset section cannot be found.
599582 """
@@ -647,7 +630,6 @@ def are_fields_on_page(
647630 ) -> bool :
648631 """
649632 Checks if the given fields are present in a section or subsection, with optional visibility checks.
650-
651633 Args:
652634 section_name (str): The name of the dataset section.
653635 subsection_name (str | None): The name of the subsection, if any.
@@ -656,7 +638,6 @@ def are_fields_on_page(
656638 - True → fields must be visible
657639 - False → fields must be not visible
658640 - None → visibility doesn't matter (just check presence)
659-
660641 Returns:
661642 bool: True if all conditions are met; False otherwise.
662643 """
@@ -680,6 +661,13 @@ def are_fields_on_page(
680661 ]
681662
682663 def label_matches (idx : int ) -> bool :
664+ """
665+ Checks if the label at the given index matches the visibility condition.
666+ Args:
667+ idx (int): The index of the label to check.
668+ Returns:
669+ bool: True if the label matches the visibility condition, False otherwise.
670+ """
683671 if visible is True :
684672 return label_elements [idx ].is_visible ()
685673 if visible is False :
@@ -726,7 +714,6 @@ def check_visibility_of_drug_type(
726714 drug_type (str): The drug type to check
727715 drug_number (int): The number of the drug type cell to check.
728716 expected_text (str): The expected text content of the cell.
729-
730717 Returns:
731718 bool: True if the visibility matches the expectation, False otherwise.
732719 """
@@ -738,12 +725,10 @@ def check_visibility_of_drug_dose(
738725 ) -> bool :
739726 """
740727 Checks the visibility of the drug dose input cell.
741-
742728 Args:
743729 drug_type (str): The drug type to check
744730 drug_number (int): The number of the drug dose cell to check.
745731 visible (bool): True if the field should be visible, False if it should not.
746-
747732 Returns:
748733 bool: True if the visibility matches the expectation, False otherwise.
749734 """
@@ -755,12 +740,10 @@ def assert_drug_type_text(
755740 ) -> None :
756741 """
757742 Asserts that the drug type input cell contains the expected text.
758-
759743 Args:
760744 drug_type (str): The drug type to check
761745 drug_number (int): The number of the drug type cell to check.
762746 expected_text (str): The expected text content of the cell.
763-
764747 Raises:
765748 AssertionError: If the actual text does not match the expected text.
766749 """
@@ -778,12 +761,10 @@ def assert_drug_dose_text(
778761 ) -> None :
779762 """
780763 Asserts that the drug dose input cell contains the expected text.
781-
782764 Args:
783765 drug_type (str): The drug type to check
784766 drug_number (int): The number of the drug dose cell to check.
785767 expected_text (str): The expected text content of the cell.
786-
787768 Raises:
788769 AssertionError: If the actual text does not match the expected text.
789770 """
@@ -799,7 +780,6 @@ def assert_drug_dose_text(
799780 def get_drug_type_locator (self , drug_type : str , drug_number : int ) -> Locator :
800781 """
801782 Returns the locator for the matching drug type and number
802-
803783 Args:
804784 drug_type (str): The drug type to check
805785 drug_number (int): The number of the drug to check
@@ -815,7 +795,6 @@ def get_drug_type_locator(self, drug_type: str, drug_number: int) -> Locator:
815795 def get_drug_dose_locator (self , drug_type : str , drug_number : int ) -> Locator :
816796 """
817797 Returns the locator for the matching drug type and number
818-
819798 Args:
820799 drug_type (str): The drug type to check
821800 drug_number (int): The number of the drug to check
@@ -833,7 +812,6 @@ def assert_drug_type_options(
833812 ) -> None :
834813 """
835814 Asserts that the options in the drug type dropdown are as expected.
836-
837815 Args:
838816 drug_type (str): The drug type to check
839817 drug_number (int): The number of the drug to check
@@ -861,7 +839,6 @@ def assert_all_drug_information(
861839 ) -> None :
862840 """
863841 Loops through a dictionary of drug types/doses and calls the relevant assertion methods
864-
865842 Args:
866843 drug_information (dict): A dictionary containing all drug types and dosages to assert
867844 drug_type_label (str): The type of drug to do the assertion against. E.g. 'Bowel Preparation Administered'
@@ -879,12 +856,12 @@ def assert_all_drug_information(
879856
880857 max_drug_number = max (drug_numbers )
881858
882- for i in range (1 , max_drug_number + 1 ):
883- drug_type = drug_information .get (f"drug_type{ i } " )
884- drug_dose = drug_information .get (f"drug_dose{ i } " )
859+ for drug_index in range (1 , max_drug_number + 1 ):
860+ drug_type = drug_information .get (f"drug_type{ drug_index } " )
861+ drug_dose = drug_information .get (f"drug_dose{ drug_index } " )
885862
886863 if drug_type is not None :
887- self .assert_drug_type_text (drug_type_label , i , drug_type )
864+ self .assert_drug_type_text (drug_type_label , drug_index , drug_type )
888865
889866 # Match-case to assert drug dose unit
890867 match drug_type :
@@ -920,15 +897,16 @@ def assert_all_drug_information(
920897 expected_unit = None
921898
922899 if expected_unit is not None :
923- self .assert_drug_dose_unit_text (drug_type_label , i , expected_unit )
900+ self .assert_drug_dose_unit_text (
901+ drug_type_label , drug_index , expected_unit
902+ )
924903
925904 if drug_dose is not None :
926- self .assert_drug_dose_text (drug_type_label , i , drug_dose )
905+ self .assert_drug_dose_text (drug_type_label , drug_index , drug_dose )
927906
928907 def get_drug_dose_unit_locator (self , drug_type : str , drug_number : int ) -> Locator :
929908 """
930909 Returns the locator for the matching drug type and number
931-
932910 Args:
933911 drug_type (str): The drug type to check
934912 drug_number (int): The number of the drug to check
@@ -946,12 +924,10 @@ def assert_drug_dose_unit_text(
946924 ) -> None :
947925 """
948926 Asserts that the drug dose unit contains the expected text.
949-
950927 Args:
951928 drug_type (str): The drug type to check
952929 drug_number (int): The number of the drug dose cell to check.
953930 expected_text (str): The expected text content of the cell.
954-
955931 Raises:
956932 AssertionError: If the actual text does not match the expected text.
957933 """
0 commit comments