e-nms_qa_automation/components_derived/user_card.py

100 lines
4.1 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.

"""Модуль компонента карточки пользователя.
Содержит класс для работы с карточкой пользователя через Playwright.
"""
from playwright.sync_api import Page
from tools.logger import get_logger
from locators.user_card_locators import UserCardLocators
from elements.text_element import Text
from elements.button_element import Button
from data.roles_dict import roles_dict
from data.environment import host
from components.base_component import BaseComponent
logger = get_logger("USER_CARD")
class UserCard(BaseComponent):
"""Компонент карточка.
Предоставляет методы для взаимодействия с элементами карточки.
"""
def __init__(self, page: Page):
"""Инициализирует компонент карточки.
Args:
page: Экземпляр страницы Playwright.
"""
super().__init__(page)
card_locator = page.locator(UserCardLocators.CARD_USER)
self.current_user_name = Text(page,
card_locator.locator("xpath=/div/div[2]"),
"current user name")
self.current_user_role = Text(page,
card_locator.locator("xpath=/div/div[3]"),
"current user role")
self.login_time = Text(page,
card_locator.locator("xpath=/div/div[4]"),
"login time")
self.session_time = Text(page,
card_locator.locator("xpath=/div/div[5]"),
"current user name")
self.logout_button = Button(
page,
page.get_by_role("button", name="Выйти"),
"logout button"
)
self.change_password_button = Button(
page,
page.get_by_role("button", name="Изменить пароль"),
"change password button"
)
self.settings_button = Button(
page,
page.get_by_role("button", name="Настройки"),
"settings button"
)
# Действия:
def click_logout_button(self):
"""Нажимает кнопку выхода из системы.
Выполняет клик по кнопке 'Выйти' в карточке пользователя.
"""
self.logout_button.click()
# Проверки:
def check_content(self):
"""Проверяет наличие и корректность элементов карточки пользователя."""
current_user_credential = host.get_current_user_credential()
name = current_user_credential["login"]
text_to_check = f"Имя пользователя: {name}"
self.current_user_name.check_have_text(text_to_check,
f"Expected text {text_to_check} is missing in user card")
role = roles_dict.get(current_user_credential["role"])
if role is None:
assert False, "Unknown user role in current user credential"
text_to_check = f"Роль: {role}"
self.current_user_role.check_have_text(text_to_check,
f"Expected text {text_to_check} is missing in user card")
login_time_str = self.login_time.get_text(0)
assert login_time_str.find("Время входа:")!= -1, \
"Expected text 'Время входа:' is missing in user card"
session_time_str = self.session_time.get_text(0)
assert session_time_str.find("Время сессии:")!= -1, \
"Expected text 'Время сессии:' is missing in user card"
self.logout_button.check_visibility("Logout button is missing on user card")
self.change_password_button.check_visibility("Change password button is missing on user card")
self.settings_button.check_visibility("Settings button is missing on user card")