62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
from selenium.webdriver.common.by import By
|
|
from .base_page import BasePage
|
|
|
|
class LoginPage(BasePage):
|
|
"""
|
|
Page Object for the Login page.
|
|
"""
|
|
|
|
# --- Locators ---
|
|
_EMAIL_INPUT = (By.ID, "email")
|
|
_PASSWORD_INPUT = (By.ID, "password")
|
|
_SIGN_IN_BUTTON = (By.XPATH, "//button[@type='submit']")
|
|
_ERROR_MESSAGE = (By.XPATH, "//p[contains(@class, 'text-red-500')]")
|
|
_LOGIN_FORM = (By.XPATH, "//form")
|
|
|
|
def __init__(self, driver):
|
|
"""Initializes the LoginPage with the WebDriver."""
|
|
super().__init__(driver)
|
|
self.page_path = "/login"
|
|
|
|
# --- Page Actions ---
|
|
|
|
def open(self, base_url: str):
|
|
"""Navigates to the login page."""
|
|
super().open(base_url, self.page_path)
|
|
|
|
def enter_email(self, email: str):
|
|
"""Enters the email into the email input field."""
|
|
self.send_keys(self._EMAIL_INPUT, email)
|
|
|
|
def enter_password(self, password: str):
|
|
"""Enters the password into the password input field."""
|
|
self.send_keys(self._PASSWORD_INPUT, password)
|
|
|
|
def click_sign_in(self):
|
|
"""Clicks the 'Sign in' button."""
|
|
self.click(self._SIGN_IN_BUTTON)
|
|
|
|
def login(self, email: str, password: str):
|
|
"""Performs a full login action."""
|
|
self.enter_email(email)
|
|
self.enter_password(password)
|
|
self.click_sign_in()
|
|
|
|
def get_error_message(self) -> str:
|
|
"""
|
|
Waits for the error message to be visible and returns its text.
|
|
Returns an empty string if the message is not found.
|
|
"""
|
|
try:
|
|
return self.find_visible_element(self._ERROR_MESSAGE).text
|
|
except:
|
|
return ""
|
|
|
|
def is_login_form_visible(self) -> bool:
|
|
"""Checks if the login form is visible on the page."""
|
|
try:
|
|
self.find_visible_element(self._LOGIN_FORM)
|
|
return True
|
|
except:
|
|
return False
|