Добавлен метод получения заголовка окна
parent
be28ffceaa
commit
93c88a12d2
|
|
@ -27,7 +27,6 @@ class ToolbarComponent(BaseComponent):
|
|||
|
||||
def __init__(self, page: Page, title: str):
|
||||
"""Инициализирует компонент тулбара с указанным заголовком."""
|
||||
|
||||
super().__init__(page)
|
||||
self.title = title
|
||||
self.buttons = []
|
||||
|
|
@ -38,7 +37,6 @@ class ToolbarComponent(BaseComponent):
|
|||
Args:
|
||||
title (str): Новый заголовок
|
||||
"""
|
||||
|
||||
self.title = title
|
||||
|
||||
def add_tooltip_button(self, locator: Locator, name: str) -> None:
|
||||
|
|
@ -48,7 +46,6 @@ class ToolbarComponent(BaseComponent):
|
|||
locator (Locator): Локатор кнопки
|
||||
name (str): Уникальное имя кнопки
|
||||
"""
|
||||
|
||||
self.buttons.append(TooltipButton(self.page, locator, name))
|
||||
|
||||
def add_tab_button(self, locator: Locator, name: str) -> None:
|
||||
|
|
@ -58,7 +55,6 @@ class ToolbarComponent(BaseComponent):
|
|||
locator (Locator): Локатор кнопки
|
||||
name (str): Уникальное имя кнопки
|
||||
"""
|
||||
|
||||
self.buttons.append(TabButton(self.page, locator, name))
|
||||
|
||||
def add_button(self, locator: Locator, name: str) -> None:
|
||||
|
|
@ -68,19 +64,17 @@ class ToolbarComponent(BaseComponent):
|
|||
locator (Locator): Локатор кнопки
|
||||
name (str): Уникальное имя кнопки
|
||||
"""
|
||||
|
||||
self.buttons.append(Button(self.page, locator, name))
|
||||
|
||||
def get_button_by_name(self, name: str) -> TooltipButton | TabButton| Button | None:
|
||||
def get_button_by_name(self, name: str) -> TooltipButton | TabButton | Button | None:
|
||||
"""Возвращает кнопку по имени.
|
||||
|
||||
Args:
|
||||
name (str): Имя кнопки
|
||||
|
||||
Returns:
|
||||
TooltipButton | TabButton| Button | None: Найденная кнопка или None
|
||||
TooltipButton | TabButton | Button | None: Найденная кнопка или None
|
||||
"""
|
||||
|
||||
for button in self.buttons:
|
||||
if button.name == name:
|
||||
return button
|
||||
|
|
@ -95,12 +89,42 @@ class ToolbarComponent(BaseComponent):
|
|||
Raises:
|
||||
AssertionError: Если кнопка не найдена
|
||||
"""
|
||||
|
||||
button = self.get_button_by_name(name)
|
||||
if button is None:
|
||||
raise AssertionError(f"Unsupported button name {name}")
|
||||
button.click()
|
||||
|
||||
def get_toolbar_title_text(self, locator: str = 'ToolbarLocators.TITLE',
|
||||
filter_text: str = None, timeout: int = 5000) -> str:
|
||||
"""Получает заголовок тулбара окна.
|
||||
|
||||
Args:
|
||||
locator: Локатор для заголовка тулбара (по умолчанию 'ToolbarLocators.TITLE')
|
||||
filter_text: Текст для фильтрации заголовка (опционально)
|
||||
timeout: Таймаут ожидания в миллисекундах
|
||||
|
||||
Returns:
|
||||
str: Текст заголовка тулбара
|
||||
|
||||
Raises:
|
||||
Exception: Если не удалось получить заголовок
|
||||
"""
|
||||
# Получаем локатор заголовка
|
||||
title_locator = self.get_locator(locator)
|
||||
|
||||
# Фильтруем по тексту если указан
|
||||
if filter_text:
|
||||
title_locator = title_locator.filter(has_text=filter_text)
|
||||
|
||||
# Ждем появления заголовка с помощью expect
|
||||
expect(title_locator).to_be_visible(timeout=timeout)
|
||||
|
||||
# Получаем текст заголовка
|
||||
title_text = title_locator.text_content().strip()
|
||||
logger.info("Заголовок тулбара: '%s'", title_text)
|
||||
|
||||
return title_text
|
||||
|
||||
def is_button_present(self, name: str) -> bool:
|
||||
"""Проверяет наличие кнопки.
|
||||
|
||||
|
|
@ -113,7 +137,6 @@ class ToolbarComponent(BaseComponent):
|
|||
Raises:
|
||||
AssertionError: Если имя кнопки не поддерживается
|
||||
"""
|
||||
|
||||
button = self.get_button_by_name(name)
|
||||
if button is None:
|
||||
raise AssertionError(f"Unsupported button name {name}")
|
||||
|
|
@ -131,7 +154,6 @@ class ToolbarComponent(BaseComponent):
|
|||
Raises:
|
||||
AssertionError: Если имя кнопки не поддерживается
|
||||
"""
|
||||
|
||||
button = self.get_button_by_name(name)
|
||||
if button is None:
|
||||
raise AssertionError(f"Unsupported button name {name}")
|
||||
|
|
@ -166,7 +188,6 @@ class ToolbarComponent(BaseComponent):
|
|||
Raises:
|
||||
AssertionError: Если кнопка не найдена или не видна
|
||||
"""
|
||||
|
||||
button = self.get_button_by_name(name)
|
||||
|
||||
if button is None:
|
||||
|
|
@ -185,7 +206,6 @@ class ToolbarComponent(BaseComponent):
|
|||
Raises:
|
||||
AssertionError: Если текст подсказки не совпадает
|
||||
"""
|
||||
|
||||
button = self.get_button_by_name(name)
|
||||
if button is None:
|
||||
raise AssertionError(f"Unsupported button name {name}")
|
||||
|
|
|
|||
Loading…
Reference in New Issue