feat(confirm_component): добавлена поддержка кастомных локаторов кнопок
- Добавлены опциональные параметры cancel_button_locator и allow_button_locator в конструктор - Текстовые параметры cancel_button_text и allow_button_text опциональными с пустыми строками по умолчанию - Добавлен приоритет локаторам над текстом кнопок при инициализации - Сохранена обратная совместимость с существующим кодомra4/management_rack
parent
46a882d2c1
commit
b46cd7870c
|
|
@ -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")
|
||||
|
||||
# Инициализация кнопок с приоритетом локаторам
|
||||
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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue