e-nms_qa_automation.1/pages/license_tab.py

103 lines
4.5 KiB
Python

from pages.base_page import BasePage
from Locators.configuration_page import ConfigurationPageLocators
from Locators.license_tab import LicenseTabLocators
from data.assertions import Assertions
from playwright.sync_api import Page
import json
class LicenseTab(BasePage):
def __init__(self, page: Page) -> None:
super().__init__(page)
self.assertion = Assertions(page)
def fill_license_input_form(self, value):
button_text = "Обновить лицензию"
self.clear_input(LicenseTabLocators.LICENSE_INPUT_FORM_TEXTAREA)
self.input(LicenseTabLocators.LICENSE_INPUT_FORM_TEXTAREA, value)
self.page.get_by_role("button", name=button_text).click()
def should_be_error_alert_window_with_text(self, text):
self.assertion.check_alert_window_with_text("error", text)
def should_be_license_work_area(self):
self.assertion.have_title(ConfigurationPageLocators.WORK_AREA_TITLE, "Лицензирование", \
"Expected work area page title is not equal real title")
self.should_be_json_content()
self.should_be_license_input_form()
def should_be_license_input_form(self):
# get form title and compare with cmdb value
form_title = "Идентификатор:"
title = self.get_text(LicenseTabLocators.LICENSE_TITLE, 0)
self.assertion.check_equals(title.strip(), form_title, \
f"Expected input form title {title} is not equal {form_title}")
device_id = self.get_text(LicenseTabLocators.LICENSE_TITLE_DEVICE_ID, 0).strip()
response = self.send_get_api_request("e-cmdb/api/lic/deviceid")
response_body = self.get_response_body(response)
self.assertion.check_equals(device_id, response_body["deviceId"], \
f"Expected ID value {device_id} is not equal {response_body['deviceId']}")
# check input form presence
self.assertion.check_presence(LicenseTabLocators.LICENSE_INPUT_FORM_TEXTAREA, \
"License input form is not present on the License work area")
# check input form button
button_text = "Обновить лицензию"
self.assertion.check_button_presence_with_text(button_text, f"License input form button with text {button_text} is not present")
def should_be_json_content(self):
def format_json_string(json_string):
substrings = json_string.splitlines()
formatted_string_list = []
last_substring = substrings.pop()
for substring in substrings:
if substring.find(':') == -1:
if substring == '{':
formatted_string_list.append(substring)
elif substring == '}':
s1 = formatted_string_list.pop()
formatted_string_list.append(s1.rstrip(','))
formatted_string_list.append(substring+ ',')
else:
formatted_string_list.append(substring + ',')
continue
key, value = substring.split(':')
s = ':'.join(['"'+key+'" '," " + value])
if value == '{':
formatted_string_list.append(s)
else:
formatted_string_list.append(s + ',')
s2 = formatted_string_list.pop()
formatted_string_list.append(s2.rstrip(','))
formatted_string_list.append(last_substring)
return " " .join(formatted_string_list)
## read json_content from work area
json_string = self.page.locator(LicenseTabLocators.JSON_ELEMENT).inner_text()
formatted_json_string = format_json_string(json_string)
expected_json_data = json.loads(formatted_json_string)
# 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.assertion.check_json_equals(expected_json_data, response_body, \
"Expected json content is not equal actual:")