e-nms_qa_automation/components/confirm_component.py

113 lines
4.5 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.

"""Модуль компонента окна подтверждения действий.
Содержит класс ConfirmComponent для взаимодействия с окном подтверждения,
включая кнопки подтверждения, отмены и закрытия, а также проверки текста.
"""
from playwright.sync_api import Page
from tools.logger import get_logger
from locators.confirm_locators import ConfirmLocators
from elements.text_element import Text
from elements.button_element import Button
from components.base_component import BaseComponent
logger = get_logger("CONFIRM_WINDOW")
class ConfirmComponent(BaseComponent):
"""Компонент окна подтверждения действий."""
def __init__(self, page: Page, cancel_button_text: str, allow_button_text: str):
"""Инициализация компонента.
Args:
page: Экземпляр страницы Playwright.
cancel_button_text: Текст кнопки отмены.
allow_button_text: Текст кнопки подтверждения.
"""
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")
self.cancel_button = Button(
page,
page.get_by_role("button", name=cancel_button_text).first,
"confirm cancel button"
)
self.allow_button = Button(
page,
page.get_by_role("button", name=allow_button_text).first,
"confirm allow button"
)
# Действия:
def click_allow_button(self) -> None:
"""Нажимает кнопку подтверждения действия."""
self.allow_button.click()
def click_cancel_button(self) -> None:
"""Нажимает кнопку отмены действия."""
self.cancel_button.click()
def click_close_button(self) -> None:
"""Нажимает кнопку закрытия окна подтверждения."""
self.close_button.click()
def scroll_window_left(self) -> None:
"""Прокручивает содержимое окна влево."""
self.scroll_left(ConfirmLocators.CONFIRM)
def scroll_window_right(self) -> None:
"""Прокручивает содержимое окна вправо."""
self.scroll_right(ConfirmLocators.CONFIRM)
# Проверки:
def check_title(self, title: str, msg: str) -> None:
"""Проверяет текст заголовка окна подтверждения.
Args:
title: Ожидаемый текст заголовка.
msg: Сообщение при ошибке.
"""
self.title.check_have_text(title, msg)
def check_text(self, text: str, msg: str) -> None:
"""Проверяет текст сообщения в окне подтверждения.
Args:
text: Ожидаемый текст сообщения.
msg: Сообщение при ошибке.
"""
self.text.check_have_text(text, msg)
def check_window_horizontal_scrolling(self) -> bool:
"""Проверяет возможность горизонтальной прокрутки окна."""
return self.is_scrollable_horizontally(ConfirmLocators.CONFIRM)
def should_be_cancel_button(self) -> None:
"""Проверяет наличие и видимость кнопки Отмены."""
self.cancel_button.check_visibility("Cancel button is missing")
def should_be_allow_button(self) -> None:
"""Проверяет наличие и видимость кнопки Подтверждения."""
self.allow_button.check_visibility("Allow button is missing")
def check_cancel_button_text(self, expected_text: str) -> None:
"""Проверяет текст кнопки Отмены."""
self.cancel_button.check_have_text(expected_text, "Cancel button text doesn't match expected")
def check_allow_button_text(self, expected_text: str) -> None:
"""Проверяет текст кнопки Подтверждения."""
self.allow_button.check_have_text(expected_text, "Allow button text doesn't match expected")