diff --git a/components_derived/accounting_objects/rack_maker.py b/components_derived/accounting_objects/rack_maker.py index 1b02517..d2de9a3 100644 --- a/components_derived/accounting_objects/rack_maker.py +++ b/components_derived/accounting_objects/rack_maker.py @@ -48,38 +48,43 @@ class RackObjectMaker(BaseComponent): """ logger.info(f"Filling rack data: {rack_data.name}") - self._fill_required_fields(rack_data) - self._fill_optional_fields(rack_data) + self._fill_text_fields(rack_data) self._fill_combobox_fields(rack_data) logger.info("Rack data filled successfully") - def _fill_required_fields(self, rack_data: RackData) -> None: - """Заполняет обязательные поля.""" - if rack_data.name: - name_field = self.page.locator(RackLocators.RACK_NAME_FIELD).first - name_field.fill(rack_data.name) - logger.info(f"Filled 'Name' field: {rack_data.name}") + def _fill_text_fields(self, rack_data: RackData) -> None: + """Заполняет текстовые поля.""" - def _fill_optional_fields(self, rack_data: RackData) -> None: - """Заполняет опциональные поля.""" + def clear_and_fill(locator, value: str, field_name: str): + """Очищает поле и заполняет его значением.""" + field = self.page.locator(locator).first + # Очищаем поле + field.click() + field.press("Control+A") + field.press("Backspace") + # Заполняем значение + field.fill(value) + logger.info(f"Filled '{field_name}': {value}") + + # Обязательные поля. + if rack_data.name: + clear_and_fill(RackLocators.RACK_NAME_FIELD, rack_data.name, "Name") + + # Опциональные поля. if rack_data.serial: - serial_field = self.page.locator(RackLocators.RACK_SERIAL_FIELD).first - serial_field.fill(rack_data.serial) - logger.info(f"Filled serial number: {rack_data.serial}") + clear_and_fill(RackLocators.RACK_SERIAL_FIELD, rack_data.serial, "Serial number") if rack_data.inventory: - inventory_field = self.page.locator(RackLocators.RACK_INVENTORY_FIELD).first - inventory_field.fill(rack_data.inventory) - logger.info(f"Filled inventory number: {rack_data.inventory}") + clear_and_fill(RackLocators.RACK_INVENTORY_FIELD, rack_data.inventory, "Inventory number") if rack_data.comment: - comment_field = self.page.locator(RackLocators.RACK_COMMENT_FIELD).first - comment_field.fill(rack_data.comment) - logger.info(f"Added comment: {rack_data.comment}") + clear_and_fill(RackLocators.RACK_COMMENT_FIELD, rack_data.comment, "Comment") def _fill_combobox_fields(self, rack_data: RackData) -> None: """Заполняет combobox поля.""" + + # Обязательные поля. if rack_data.height: self._fill_combobox_field("Height in units", rack_data.height, RackLocators.RACK_HEIGHT_FIELD) @@ -90,6 +95,7 @@ class RackObjectMaker(BaseComponent): RackLocators.RACK_DEPTH_FIELD) logger.info(f"Selected depth: {rack_data.depth} mm") + # Опциональные поля. if rack_data.cable_entry: self._fill_combobox_field("Cable entry", rack_data.cable_entry, RackLocators.RACK_CABLE_ENTRY_FIELD) diff --git a/components_derived/frames/create_child_element_frame.py b/components_derived/frames/create_child_element_frame.py index 62db7b9..908f5d2 100644 --- a/components_derived/frames/create_child_element_frame.py +++ b/components_derived/frames/create_child_element_frame.py @@ -237,7 +237,7 @@ class CreateChildElementFrame(BaseComponent): # Методы проверки ошибок полей (используют SelectionBarComponent) - def check_field_highlighted_error(self, field_name: str) -> None: + def check_field_error_highlighted(self, field_name: str) -> None: """ Проверяет, что поле подсвечено цветом ошибки (валидация не пройдена). @@ -245,9 +245,9 @@ class CreateChildElementFrame(BaseComponent): field_name: Название поля для проверки """ field_locator = self._get_field_locator(field_name) - self.selection_bar.check_field_highlighted_error(field_name, field_locator) + self.selection_bar.check_field_error_highlighted(field_name, field_locator) - def check_field_not_highlighted_error(self, field_name: str) -> None: + def check_field_error_not_highlighted(self, field_name: str) -> None: """ Проверяет, что поле НЕ подсвечено цветом ошибки (валидация успешна). @@ -255,4 +255,4 @@ class CreateChildElementFrame(BaseComponent): field_name: Название поля для проверки """ field_locator = self._get_field_locator(field_name) - self.selection_bar.check_field_not_highlighted_error(field_name, field_locator) + self.selection_bar.check_field_error_not_highlighted(field_name, field_locator) diff --git a/components_derived/selection_bar_component.py b/components_derived/selection_bar_component.py index 52837a9..5f8e661 100644 --- a/components_derived/selection_bar_component.py +++ b/components_derived/selection_bar_component.py @@ -162,7 +162,7 @@ class SelectionBarComponent(BaseComponent): # Проверки: - def check_field_highlighted_error(self, field_name: str, field_locator: str) -> None: + def check_field_error_highlighted(self, field_name: str, field_locator: str) -> None: """Проверяет, что поле подсвечено цветом ошибки (валидация не пройдена). Args: @@ -188,7 +188,7 @@ class SelectionBarComponent(BaseComponent): logger.info(f"Field '{field_name}' is correctly highlighted with error color") - def check_field_not_highlighted_error(self, field_name: str, field_locator: str) -> None: + def check_field_error_not_highlighted(self, field_name: str, field_locator: str) -> None: """Проверяет, что поле НЕ подсвечено цветом ошибки (валидация успешна). Args: diff --git a/tests/e2e/create_elements/test_create_rack_element.py b/tests/e2e/create_elements/test_create_rack_element.py index e2def45..a72f70b 100644 --- a/tests/e2e/create_elements/test_create_rack_element.py +++ b/tests/e2e/create_elements/test_create_rack_element.py @@ -24,6 +24,10 @@ class TestCreateRackElement: 4. test_required_fields_validation: Проверяет валидацию обязательных полей при создании стойки """ + # Инициализируем атрибуты + main_page: MainPage = None + location_page: LocationPage = None + @pytest.fixture(scope="function", autouse=True) def setup(self, browser: Page) -> None: """Фикстура для подготовки тестового окружения. @@ -227,14 +231,14 @@ class TestCreateRackElement: # Проверяем подсветку полей if height_value: - create_child_frame.check_field_not_highlighted_error("Высота в юнитах") + create_child_frame.check_field_error_not_highlighted("Высота в юнитах") else: - create_child_frame.check_field_highlighted_error("Высота в юнитах") + create_child_frame.check_field_error_highlighted("Высота в юнитах") if depth_value: - create_child_frame.check_field_not_highlighted_error("Глубина (мм)") + create_child_frame.check_field_error_not_highlighted("Глубина (мм)") else: - create_child_frame.check_field_highlighted_error("Глубина (мм)") + create_child_frame.check_field_error_highlighted("Глубина (мм)") # Обрабатываем alert-окна if not height_value: @@ -347,9 +351,9 @@ class TestCreateRackElement: rack_maker.fill_rack_data(rack_data) # Проверяем, что ни одно поле не подсвечено цветом ошибки - create_child_frame.check_field_not_highlighted_error("Имя") - create_child_frame.check_field_not_highlighted_error("Высота в юнитах") - create_child_frame.check_field_not_highlighted_error("Глубина (мм)") + create_child_frame.check_field_error_not_highlighted("Имя") + create_child_frame.check_field_error_not_highlighted("Высота в юнитах") + create_child_frame.check_field_error_not_highlighted("Глубина (мм)") logger.info("No required fields are highlighted with error color - all fields filled correctly") # Нажимаем кнопку создания