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: