47 lines
2.1 KiB
Python
47 lines
2.1 KiB
Python
from playwright.sync_api import Page, Locator
|
||
|
||
from components.base_component import BaseComponent
|
||
from locators.navigation_panel_locators import NavigationPanelLocators
|
||
|
||
from tools.logger import get_logger
|
||
|
||
logger = get_logger("NAVIGATION_PANEL")
|
||
|
||
|
||
class NavigationPanelComponent(BaseComponent):
|
||
"""Компонент панели навигации."""
|
||
|
||
def __init__(self, page: Page):
|
||
super().__init__(page)
|
||
|
||
# Действия:
|
||
def get_item_names(self, locator: str | Locator) -> list[str]:
|
||
"""Получает тексты всех элементов по указанному локатору."""
|
||
loc = self.get_locator(locator)
|
||
return loc.all_inner_texts()
|
||
|
||
def click_item(self, locator: str | Locator, item_name: str) -> None:
|
||
"""Кликает по элементу с указанным текстом."""
|
||
loc = self.get_locator(locator)
|
||
loc.get_by_text(item_name).click()
|
||
|
||
def click_sub_item(self, locator: str | Locator, sublevel_number: int, item_name: str) -> None:
|
||
"""Кликает по вложенному элементу с указанным текстом."""
|
||
root_locator = self.get_locator(NavigationPanelLocators.NODE_ROOT)
|
||
children_locator = self.get_locator(NavigationPanelLocators.NODE_CHILDREN)
|
||
|
||
loc = self.get_locator(locator)
|
||
|
||
if sublevel_number == 1:
|
||
loc.locator(root_locator).get_by_text(item_name).click()
|
||
elif sublevel_number == 2:
|
||
loc.locator(children_locator).locator(root_locator).get_by_text(item_name).click()
|
||
else:
|
||
raise ValueError("the navigation panel has two levels of nesting only")
|
||
|
||
# Проверки:
|
||
def check_item_visibility(self, locator: str | Locator, item_name: str) -> None:
|
||
"""Проверяет видимость элемента с указанным текстом."""
|
||
loc = self.get_locator(locator).get_by_text(item_name)
|
||
msg = f"Navigation panel item '{item_name}' is not visible"
|
||
self.check_presence(loc, msg) |