e-nms_qa_automation/pages/license_tab.py

153 lines
7.2 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.

from pages.base_page import BasePage
from components.alert_component import AlertComponent
from elements.button_element import Button
from components.json_container_component import JsonContainerComponent
from elements.text_element import Text
from elements.text_input_element import TextInput
from components.toolbar_component import ToolbarComponent
from locators.button_locators import ButtonLocators
from locators.json_container_locators import JsonContainerLocators
from locators.input_locators import InputLocators
from locators.text_locators import TextLocators
from playwright.sync_api import Page
class LicenseTab(BasePage):
"""Класс для работы с вкладкой 'Лицензии'.
Атрибуты:
page (Page): Экземпляр страницы Playwright.
toolbar (ToolbarComponent): Компонент панели инструментов.
json_container (JsonContainerComponent): Компонент контейнера с JSON-данными.
input_form_title (Text): Заголовок формы ввода.
license_id (Text): Текстовый элемент с идентификатором лицензии.
license_id_input (TextInput): Поле ввода идентификатора лицензии.
update_button (Button): Кнопка обновления лицензии.
error_alert (AlertComponent): Компонент алерта с ошибкой.
"""
def __init__(self, page: Page) -> None:
"""Инициализирует элементы вкладки 'Лицензии'.
Args:
page: Экземпляр страницы Playwright.
"""
super().__init__(page)
self.toolbar = ToolbarComponent(page, "Лицензии")
self.json_container = JsonContainerComponent(page)
self.input_form_title = Text(page, TextLocators.TITLE_LICENSE_INPUT_FORM, "input form title")
self.license_id = Text(page, TextLocators.LICENSE_ID, "license id")
self.license_id_input = TextInput(page, InputLocators.LICENSE_ID_UPDATE, "license id input")
self.update_button = Button(page, ButtonLocators.BUTTON_LICENSE_UPDATE, "update license button")
self.error_alert = AlertComponent(page, "error")
# Действия:
def fill_license_input_form(self, value: str) -> None:
"""Заполняет форму ввода идентификатора лицензии и нажимает кнопку обновления.
Args:
value: Значение для ввода в поле идентификатора лицензии.
"""
self.license_id_input.clear()
self.license_id_input.input_value(value)
self.update_button.click()
def scroll_json_container_up(self) -> None:
"""Прокручивает JSON-контейнер вверх."""
loc = self.page.locator(JsonContainerLocators.SCROLL_CONTAINER).first
self.json_container.scroll_up(loc)
def scroll_json_container_down(self) -> None:
"""Прокручивает JSON-контейнер вниз."""
loc = self.page.locator(JsonContainerLocators.SCROLL_CONTAINER).first
self.json_container.scroll_down(loc)
# Проверки:
def check_json_container_verticall_scrolling(self) -> bool:
"""Проверяет возможность вертикальной прокрутки JSON-контейнера.
Returns:
bool: True если контейнер можно прокручивать, иначе False.
"""
loc = self.page.locator(JsonContainerLocators.SCROLL_CONTAINER).first
return self.json_container.is_scrollable_vertically(loc)
def check_content(self) -> None:
"""Проверяет наличие всех основных элементов на вкладке."""
self.should_be_toolbar()
self.should_be_json_container()
self.should_be_input_form_title()
self.should_be_empty_input_form()
self.should_be_update_button()
def should_be_error_alert_window_with_text(self, text: str) -> None:
"""Проверяет наличие и отсутствие алерта с указанным текстом.
Args:
text: Текст для проверки в алерте.
"""
self.error_alert.check_presence(text)
self.error_alert.check_absence(text)
def should_be_toolbar(self) -> None:
"""Проверяет наличие панели инструментов."""
self.toolbar.check_presence("Toolbar is missing")
def should_be_json_container(self) -> None:
"""Проверяет наличие JSON-контейнера с информацией о лицензии."""
self.json_container.check_presence(
JsonContainerLocators.CONTAINER,
"Json container with license info is missing"
)
def should_be_input_form_title(self) -> None:
"""Проверяет заголовок формы ввода и соответствие ID лицензии."""
self.input_form_title.check_have_text(
"Идентификатор:",
"Input lisence id form title 'Идентификатор:' is missing"
)
actual_lisence_id = self.license_id.get_text(0).strip()
# send request to backend to get license id
response = self.send_get_api_request("e-cmdb/api/lic/deviceid")
response_body = self.get_response_body(response)
self.check_equals(
actual_lisence_id,
response_body['deviceId'],
f"Expected ID value {response_body['deviceId']} is not equal actual value {actual_lisence_id}"
)
def should_be_empty_input_form(self) -> None:
"""Проверяет, что форма ввода идентификатора лицензии пуста."""
self.license_id_input.check_empty_input("Input lisence id form is missing or not empty")
def should_be_update_button(self) -> None:
"""Проверяет наличие кнопки обновления лицензии с правильным текстом."""
button_text = "Обновить лицензию"
self.update_button.check_have_text(
button_text,
f"Update button with text '{button_text}' is missing"
)
def verify_json_container_content(self) -> None:
"""Проверяет соответствие содержимого JSON-контейнера данным из API."""
actual_data = self.json_container.read_data(JsonContainerLocators.CONTAINER)
# send request to backend to get license info
response = self.send_get_api_request("e-cmdb/api/lic")
response_body = self.get_response_body(response)
## temporarily
del response_body["netManagment"]
response_body["ui"].pop("lcc")
self.json_container.check_json_equals(
actual_data,
response_body,
"Expected json content is not equal actual:"
)