e-nms_qa_automation/pages/location_page.py

83 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""Модуль страницы локации."""
from playwright.sync_api import Page
from components.toolbar_component import ToolbarComponent
from components_derived.frames.create_child_element_frame import (
CreateChildElementFrame
)
from pages.base_page import BasePage
# =============== Локаторы ================================================
PANEL_HEADER = "//span[text()='Объекты']/following-sibling::i"
CREATE_BUTTON_ANCESTOR_DIV3 = "xpath=/ancestor::div[3]//button"
# =========================================================================
class LocationPage(BasePage):
"""Класс для работы со страницей локации."""
def __init__(self, page: Page) -> None:
"""
Инициализирует страницу локации.
Args:
page: Экземпляр страницы Playwright
"""
super().__init__(page)
# Инициализация тулбара
self.toolbar = ToolbarComponent(page, "")
panel_header_locator = self.page.locator(PANEL_HEADER)
# Кнопка "Создать" - первая кнопка в тулбаре
create_button_locator = panel_header_locator.locator(
CREATE_BUTTON_ANCESTOR_DIV3
).nth(0)
# Инициализация кнопки
self.toolbar.add_tooltip_button(create_button_locator, "create")
# Инициализация фреймов (ленивая загрузка)
self._create_child_frame = None
def click_create_button(self) -> CreateChildElementFrame:
"""
Кликает на кнопку 'Создать' и возвращает фрейм создания.
Returns:
CreateChildElementFrame: Фрейм создания дочернего элемента
"""
# Используем метод тулбара для клика
self.toolbar.click_button("create")
self.wait_for_timeout(3000)
# Создаем и возвращаем фрейм
self._create_child_frame = CreateChildElementFrame(self.page)
return self._create_child_frame
def is_create_button_visible(self) -> bool:
"""
Проверяет видимость кнопки 'Создать'.
Returns:
bool: True если кнопка видима
"""
button = self.toolbar.get_button_by_name("create")
if button is None:
return False
return button.is_present(timeout=5000) and button.locator.is_visible()
def wait_for_timeout(self, timeout: int) -> None:
"""
Ожидает указанное количество миллисекунд.
Args:
timeout: Время ожидания в миллисекундах
"""
self.page.wait_for_timeout(timeout)