"""Модуль вкладки настройки СМС уведомлений. Содержит класс SMSNotificationsSettings для работы с вкладкой настройки СМС уведомлений. Позволяет проверять состояние и взаимодействовать с элементами вкладки. """ import re from playwright.sync_api import Page from locators.text_input_locators import TextInputLocators from locators.settings_form_locators import SettingsFormLocators from elements.text_input_element import TextInput from elements.icon_element import Icon from components.toolbar_component import ToolbarComponent from components_derived.settings_form_component import SettingsFormComponent from components_derived.modal_send_test_sms import SendTestSMSModalWindow from pages.base_page import BasePage class SMSNotificationsSettingsTab(BasePage): """Класс для работы с вкладкой настройки СМС уведомлений. Предоставляет методы для взаимодействия с вкладкой настройки СМС уведомлений. Args: page: Экземпляр страницы Playwright. """ def __init__(self, page: Page) -> None: """Инициализирует компоненты вкладки настройки СМС уведомлений.""" super().__init__(page) self.toolbar = ToolbarComponent(page, "СМС") toolbar_button_edit = self.page.get_by_role("navigation").filter(has_text=re.compile("СМС")). \ locator("//button[@data-testid='NOTIFICATIONS_SMS__btn__edit']") self.toolbar.add_tooltip_button(toolbar_button_edit, "edit") toolbar_button_save = self.page.get_by_role("navigation").filter(has_text=re.compile("СМС")). \ locator("//button[@data-testid='NOTIFICATIONS_SMS__btn__submit']") self.toolbar.add_tooltip_button(toolbar_button_save, "save") toolbar_button_cancel = self.page.get_by_role("navigation").filter(has_text=re.compile("СМС")). \ locator("//button[@data-testid='NOTIFICATIONS_SMS__btn__cancelEdit']") self.toolbar.add_tooltip_button(toolbar_button_cancel, "cancel") # Форма для отображения/редактирования полей настроек СМС уведомлений self.settings_form = SettingsFormComponent(page) container_locator = self.page.locator(SettingsFormLocators.SETTINGS_FORM_SMS_INPUT_FORM_CONTAINER) self.input_fields_locators = self.settings_form.get_input_fields_locators(container_locator) loc = self.input_fields_locators.get("ip") loc_message_input = loc.locator("//input[@data-testid='NOTIFICATIONS_SMS__text-field__ip']") ip_setting_input = TextInput(page, loc_message_input, "ip_setting_input") self.settings_form.add_content_item("ip_setting_input", ip_setting_input) loc = self.input_fields_locators.get("Имя пользователя") loc_user_input = loc.locator("//input[@data-testid='NOTIFICATIONS_SMS__text-field__login']") user_setting_input = TextInput(page, loc_user_input, "user_setting_input") self.settings_form.add_content_item("user_setting_input", user_setting_input) loc = self.input_fields_locators.get("Пароль") loc_password_input = loc.locator("//input[@data-testid='NOTIFICATIONS_SMS__text-field__password']") password_setting_input = TextInput(page, loc_password_input, "password_setting_input") self.settings_form.add_content_item("password_setting_input", password_setting_input) icon_locator = loc_password_input.locator("../..").locator(TextInputLocators.ICON_PASSWORD_HIDING) password_hidden_icon = Icon(page, icon_locator, "password hidden icon") self.settings_form.add_content_item("password_hidden_icon", password_hidden_icon) self.settings_form.add_tooltip_button(page.locator(SettingsFormLocators.SETTTINGS_FORM_SCROLL_CONTAINER).\ locator("//button[@data-testid='NOTIFICATIONS_SMS__btn__onSelect']"), "test_button") # Действия: def click_cancel_button(self) -> None: """Нажатие кнопки 'Отменить' на тулбаре.""" self.toolbar.check_button_visibility("cancel") self.toolbar.get_button_by_name("cancel").click() def click_edit_button(self) -> None: """Нажатие кнопки 'Редактировать' на тулбаре.""" self.toolbar.check_button_visibility("edit") self.toolbar.get_button_by_name("edit").click() def click_save_button(self) -> None: """Нажатие кнопки 'Сохранить' на тулбаре.""" self.toolbar.check_button_visibility("save") self.toolbar.get_button_by_name("save").click() def click_password_hidden_icon(self) -> None: """Нажатие на иконку скрытия пароля.""" self.settings_form.get_content_item("password_hidden_icon").click() def click_test_button(self) -> SendTestSMSModalWindow: """Нажатие кнопки 'Тест' в форме ввода настроек.""" self.settings_form.check_button_visibility("test_button") self.settings_form.get_button_by_name("test_button").click() return SendTestSMSModalWindow(self.page) def get_ip_setting_value(self) -> str: """Возвращает текущее значение поля настроек 'IP'. Returns: str : Текущее значение поля настроек 'IP'. """ input_field = self.settings_form.get_content_item("ip_setting_input") return input_field.get_input_value().strip() def get_user_setting_value(self) -> str: """Возвращает текущее значение поля настроек 'Имя пользователя'. Returns: str : Текущее значение поля настроек 'Имя пользователя'. """ input_field = self.settings_form.get_content_item("user_setting_input") return input_field.get_input_value().strip() def get_password_setting_value(self) -> str: """Возвращает текущее значение поля настроек 'Пароль'. Returns: str : Текущее отображение значения поля настроек 'Пароль'. """ input_field = self.settings_form.get_content_item("password_setting_input") is_hidden_state = self.settings_form.get_content_item("password_hidden_icon").is_password_hidden() password_value = input_field.get_input_value().strip() if is_hidden_state: password_value = "." * len(password_value) return password_value def input_ip(self, text: str) -> None: """Заполнение поля 'IP'.""" message_input = self.settings_form.get_content_item("ip_setting_input") message_input.clear() message_input.input_value(text) def input_user(self, text: str) -> None: """Заполнение поля 'Имя пользователя'.""" message_input = self.settings_form.get_content_item("user_setting_input") message_input.clear() message_input.input_value(text) def input_password(self, text: str) -> None: """Заполнение поля 'Пароль'.""" message_input = self.settings_form.get_content_item("password_setting_input") message_input.clear() message_input.input_value(text) # Проверки: def check_content(self): """Проверяет наличие и корректность всех элементов страницы.""" expected_input_field_names = ["ip", "Имя пользователя", "Пароль"] self.should_be_toolbar() actual_input_field_names = self.input_fields_locators.keys() assert set(actual_input_field_names) == set(expected_input_field_names), \ f"Misscomparison input field names: Expected {expected_input_field_names}, Actual {actual_input_field_names}" for name in self.settings_form.content_items.keys(): item = self.settings_form.get_content_item(name) item.check_visibility( f"SMS notifications settings input form item with name '{name}' is missing" ) if name == "password_hidden_icon": is_hidden_state = item.is_password_hidden() assert is_hidden_state, "Password hidden icon should be in hidden state" self.settings_form.check_button_visibility("test_button") self.settings_form.check_button_tooltip("test_button", "Тест") def should_be_toolbar(self) -> None: """Проверяет наличие тулбара страницы, наличие и функциональность кнопок тулбара. Raises: AssertionError: Если тулбар или кнопка тулбара отсутствуют. """ loc = self.page.get_by_role("navigation").filter( has_text=re.compile("СМС")).locator("div").nth(1) self.toolbar.check_toolbar_presence_by_locator(loc, "Toolbar with title 'СМС' is missing") self.toolbar.check_button_visibility("edit") self.toolbar.check_button_tooltip("edit", "Редактировать") self.toolbar.get_button_by_name("edit").click() self.toolbar.check_button_visibility("save") self.toolbar.check_button_visibility("cancel") self.toolbar.check_button_tooltip("save", "Сохранить") self.toolbar.check_button_tooltip("cancel", "Отменить") self.toolbar.get_button_by_name("cancel").click() self.toolbar.check_button_visibility("edit") def should_be_test_button(self) -> None: """Проверяет наличие кнопки 'Тест'. Raises: AssertionError: Если кнопка отсутствует. """ self.settings_form.check_button_visibility("test_button")