e-nms_qa_automation.1/pages/login_page.py

59 lines
2.6 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 data.constants import Constants
from Locators.login import LoginPageLocators
from data.assertions import Assertions
from data.environment import host
from playwright.sync_api import Page
class LoginPage(BasePage):
def __init__(self, page: Page) -> None:
super().__init__(page)
self.token = ""
self.assertion = Assertions(page)
def do_login(self, username: str = None, password: str = None):
"""Выполняет вход в систему.
Если username/password не указаны, использует значения из Constants"""
def handle_response(response):
if "login" in response.url:
response_body = self.get_response_body(response)
if response_body:
token = response_body.get("access_token")
host.set_access_token(token)
self.page.on("response", handle_response)
self.open("")
# Используем переданные значения или значения по умолчанию из Constants
actual_username = username if username is not None else Constants.login
actual_password = password if password is not None else Constants.password
self.clear_input(LoginPageLocators.USERNAME_INPUT)
self.input(LoginPageLocators.USERNAME_INPUT, actual_username)
self.clear_input(LoginPageLocators.PASSWORD_INPUT)
self.input(LoginPageLocators.PASSWORD_INPUT, actual_password)
self.click(LoginPageLocators.LOGIN_BTN)
self.assertion.check_URL("dashboard", "An unexpected page has been opened")
def do_unsuccessful_login(self, username: str = "someuser", password: str = "password"):
"""Выполняет попытку входа с неверными учетными данными.
Можно передать свои неверные данные или использовать значения по умолчанию"""
incorrect_credentials_text = "Неверная пара логин/пароль"
self.open("")
self.clear_input(LoginPageLocators.USERNAME_INPUT)
self.input(LoginPageLocators.USERNAME_INPUT, username)
self.clear_input(LoginPageLocators.PASSWORD_INPUT)
self.input(LoginPageLocators.PASSWORD_INPUT, password)
self.click(LoginPageLocators.LOGIN_BTN)
self.assertion.check_alert_window_with_text("error", incorrect_credentials_text)