From b46cd7870c7dea2748d414b168213b184545a2c8 Mon Sep 17 00:00:00 2001 From: Radislav Date: Wed, 28 Jan 2026 14:52:11 +0300 Subject: [PATCH] =?UTF-8?q?feat(confirm=5Fcomponent):=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20=D0=BA=D0=B0=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=BC=D0=BD=D1=8B=D1=85=20=D0=BB=D0=BE=D0=BA=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Добавлены опциональные параметры cancel_button_locator и allow_button_locator в конструктор - Текстовые параметры cancel_button_text и allow_button_text опциональными с пустыми строками по умолчанию - Добавлен приоритет локаторам над текстом кнопок при инициализации - Сохранена обратная совместимость с существующим кодом --- components/confirm_component.py | 45 +++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/components/confirm_component.py b/components/confirm_component.py index 5ee0e37..6467e2c 100644 --- a/components/confirm_component.py +++ b/components/confirm_component.py @@ -17,31 +17,48 @@ logger = get_logger("CONFIRM_WINDOW") class ConfirmComponent(BaseComponent): """Компонент окна подтверждения действий.""" - def __init__(self, page: Page, cancel_button_text: str, allow_button_text: str): + def __init__(self, page: Page, cancel_button_text: str = "", allow_button_text: str = "", + cancel_button_locator: str = None, allow_button_locator: str = None): """Инициализация компонента. Args: page: Экземпляр страницы Playwright. - cancel_button_text: Текст кнопки отмены. - allow_button_text: Текст кнопки подтверждения. + cancel_button_text: Текст кнопки отмены (по умолчанию пустая строка). + allow_button_text: Текст кнопки подтверждения (по умолчанию пустая строка). + cancel_button_locator: Локатор кнопки отмены (опционально). + allow_button_locator: Локатор кнопки подтверждения (опционально). """ super().__init__(page) self.title = Text(page, ConfirmLocators.TITLE, "confirm title") self.text = Text(page, ConfirmLocators.TEXT, "confirm text") - self.close_button = Button(page, ConfirmLocators.BUTTON_CLOSE, "confirm close button") - self.cancel_button = Button( - page, - page.get_by_role("button", name=cancel_button_text).first, - "confirm cancel button" - ) - self.allow_button = Button( - page, - page.get_by_role("button", name=allow_button_text).first, - "confirm allow button" - ) + + # Инициализация кнопок с приоритетом локаторам + if cancel_button_locator: + self.cancel_button = Button(page, cancel_button_locator, "confirm cancel button") + elif cancel_button_text: + self.cancel_button = Button( + page, + page.get_by_role("button", name=cancel_button_text).first, + "confirm cancel button" + ) + else: + self.cancel_button = None + logger.warning("Cancel button not initialized - neither text nor locator specified") + + if allow_button_locator: + self.allow_button = Button(page, allow_button_locator, "confirm allow button") + elif allow_button_text: + self.allow_button = Button( + page, + page.get_by_role("button", name=allow_button_text).first, + "confirm allow button" + ) + else: + self.allow_button = None + logger.warning("Allow button not initialized - neither text nor locator specified") # Действия: def click_allow_button(self) -> None: