Учтены замечания code-review

radislav/tests_rack
Radislav 2025-12-08 07:22:50 +03:00
parent 575b92a869
commit fd9af2c711
4 changed files with 42 additions and 32 deletions

View File

@ -48,38 +48,43 @@ class RackObjectMaker(BaseComponent):
""" """
logger.info(f"Filling rack data: {rack_data.name}") logger.info(f"Filling rack data: {rack_data.name}")
self._fill_required_fields(rack_data) self._fill_text_fields(rack_data)
self._fill_optional_fields(rack_data)
self._fill_combobox_fields(rack_data) self._fill_combobox_fields(rack_data)
logger.info("Rack data filled successfully") logger.info("Rack data filled successfully")
def _fill_required_fields(self, rack_data: RackData) -> None: def _fill_text_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_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: if rack_data.serial:
serial_field = self.page.locator(RackLocators.RACK_SERIAL_FIELD).first clear_and_fill(RackLocators.RACK_SERIAL_FIELD, rack_data.serial, "Serial number")
serial_field.fill(rack_data.serial)
logger.info(f"Filled serial number: {rack_data.serial}")
if rack_data.inventory: if rack_data.inventory:
inventory_field = self.page.locator(RackLocators.RACK_INVENTORY_FIELD).first clear_and_fill(RackLocators.RACK_INVENTORY_FIELD, rack_data.inventory, "Inventory number")
inventory_field.fill(rack_data.inventory)
logger.info(f"Filled inventory number: {rack_data.inventory}")
if rack_data.comment: if rack_data.comment:
comment_field = self.page.locator(RackLocators.RACK_COMMENT_FIELD).first clear_and_fill(RackLocators.RACK_COMMENT_FIELD, rack_data.comment, "Comment")
comment_field.fill(rack_data.comment)
logger.info(f"Added comment: {rack_data.comment}")
def _fill_combobox_fields(self, rack_data: RackData) -> None: def _fill_combobox_fields(self, rack_data: RackData) -> None:
"""Заполняет combobox поля.""" """Заполняет combobox поля."""
# Обязательные поля.
if rack_data.height: if rack_data.height:
self._fill_combobox_field("Height in units", rack_data.height, self._fill_combobox_field("Height in units", rack_data.height,
RackLocators.RACK_HEIGHT_FIELD) RackLocators.RACK_HEIGHT_FIELD)
@ -90,6 +95,7 @@ class RackObjectMaker(BaseComponent):
RackLocators.RACK_DEPTH_FIELD) RackLocators.RACK_DEPTH_FIELD)
logger.info(f"Selected depth: {rack_data.depth} mm") logger.info(f"Selected depth: {rack_data.depth} mm")
# Опциональные поля.
if rack_data.cable_entry: if rack_data.cable_entry:
self._fill_combobox_field("Cable entry", rack_data.cable_entry, self._fill_combobox_field("Cable entry", rack_data.cable_entry,
RackLocators.RACK_CABLE_ENTRY_FIELD) RackLocators.RACK_CABLE_ENTRY_FIELD)

View File

@ -237,7 +237,7 @@ class CreateChildElementFrame(BaseComponent):
# Методы проверки ошибок полей (используют SelectionBarComponent) # Методы проверки ошибок полей (используют 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_name: Название поля для проверки
""" """
field_locator = self._get_field_locator(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_name: Название поля для проверки
""" """
field_locator = self._get_field_locator(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)

View File

@ -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: Args:
@ -188,7 +188,7 @@ class SelectionBarComponent(BaseComponent):
logger.info(f"Field '{field_name}' is correctly highlighted with error color") 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: Args:

View File

@ -24,6 +24,10 @@ class TestCreateRackElement:
4. test_required_fields_validation: Проверяет валидацию обязательных полей при создании стойки 4. test_required_fields_validation: Проверяет валидацию обязательных полей при создании стойки
""" """
# Инициализируем атрибуты
main_page: MainPage = None
location_page: LocationPage = None
@pytest.fixture(scope="function", autouse=True) @pytest.fixture(scope="function", autouse=True)
def setup(self, browser: Page) -> None: def setup(self, browser: Page) -> None:
"""Фикстура для подготовки тестового окружения. """Фикстура для подготовки тестового окружения.
@ -227,14 +231,14 @@ class TestCreateRackElement:
# Проверяем подсветку полей # Проверяем подсветку полей
if height_value: if height_value:
create_child_frame.check_field_not_highlighted_error("Высота в юнитах") create_child_frame.check_field_error_not_highlighted("Высота в юнитах")
else: else:
create_child_frame.check_field_highlighted_error("Высота в юнитах") create_child_frame.check_field_error_highlighted("Высота в юнитах")
if depth_value: if depth_value:
create_child_frame.check_field_not_highlighted_error("Глубина (мм)") create_child_frame.check_field_error_not_highlighted("Глубина (мм)")
else: else:
create_child_frame.check_field_highlighted_error("Глубина (мм)") create_child_frame.check_field_error_highlighted("Глубина (мм)")
# Обрабатываем alert-окна # Обрабатываем alert-окна
if not height_value: if not height_value:
@ -347,9 +351,9 @@ class TestCreateRackElement:
rack_maker.fill_rack_data(rack_data) rack_maker.fill_rack_data(rack_data)
# Проверяем, что ни одно поле не подсвечено цветом ошибки # Проверяем, что ни одно поле не подсвечено цветом ошибки
create_child_frame.check_field_not_highlighted_error("Имя") create_child_frame.check_field_error_not_highlighted("Имя")
create_child_frame.check_field_not_highlighted_error("Высота в юнитах") create_child_frame.check_field_error_not_highlighted("Высота в юнитах")
create_child_frame.check_field_not_highlighted_error("Глубина (мм)") create_child_frame.check_field_error_not_highlighted("Глубина (мм)")
logger.info("No required fields are highlighted with error color - all fields filled correctly") logger.info("No required fields are highlighted with error color - all fields filled correctly")
# Нажимаем кнопку создания # Нажимаем кнопку создания