e-nms_qa_automation/components/expand_button_component.py

73 lines
2.7 KiB
Python
Raw Permalink 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.

"""Модуль expand_button_component содержит класс для работы с кнопкой расширения/уменьшения рабочей области вкладки
на странице."""
from playwright.sync_api import Page
from tools.logger import get_logger
from elements.button_element import Button
from components.base_component import BaseComponent
logger = get_logger("EXPAND_BUTTON")
class ExpandButton(BaseComponent):
"""Класс для работы с кнопкой расширения/сжатия рабочей области вкладки на странице.
"""
def __init__(self, page: Page):
"""Инициализирует компонент.
Args:
page: Экземпляр страницы Playwright.
"""
super().__init__(page)
self.expand_work_area_button_locator = page.get_by_role("button").filter(has_text="navigate_")
self.expand_work_area_button = Button(page,
self.expand_work_area_button_locator,
"expand_work_area_button")
# Действия:
def expand(self) -> None:
"""Нажатие кнопки для расширения рабочей области вкладки"""
can_do_expand = self.is_in_expand_state()
if can_do_expand:
self.expand_work_area_button.click()
else:
assert False, "Work area already expanded"
def reduce(self) -> None:
"""Нажатие кнопки для сжатия рабочей области вкладки"""
can_do_expand = self.is_in_expand_state()
if can_do_expand:
assert False, "Work area already reduced"
else:
self.expand_work_area_button.click()
# Проверки:
def is_in_expand_state(self) -> bool:
"""Проверяет состояние кнопки, способность ее увеличить размер рабочей области вкладки"""
button_state = self.expand_work_area_button_locator.text_content()
if button_state.find("before") != -1:
return True
elif button_state.find("next") != -1:
return False
else:
assert False, f"Got unexpected button state {button_state}"
def should_be_button(self) -> None:
"""Проверяет наличие кнопки расширения/сжатия рабочей области вкладки.
Raises:
AssertionError: Если кнопка отсутствует.
"""
self.expand_work_area_button.check_visibility(
"Expand work area button is missing on page"
)