e-nms_qa_automation/components/confirm_component.py

82 lines
3.0 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.

"""Модуль компонента окна подтверждения действий.
Содержит класс 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 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)