selenium_automation_project/page_objects/home_page.py

50 lines
1.7 KiB
Python

from selenium.webdriver.common.by import By
from .base_page import BasePage
class HomePage(BasePage):
"""
Page Object for the Home page (Dashboard).
"""
# --- Locators ---
_WELCOME_MESSAGE = (By.XPATH, '//*[@id="root"]/div/main/div/div[1]/h1')
_LOGOUT_BUTTON = (By.XPATH, "//button[text()='Logout']")
_PROFILE_TAB = (By.XPATH, "//button[@role='tab' and text()='Profile']")
_DASHBOARD_CONTENT = (By.XPATH, '/html/body/div/div/main/div/div[2]/div[2]/div')
_DASHBORAD_TEST_CASES_TITLE = (By.XPATH,'//*[contains(@id,"content-dashboard")]/div/div[1]//h3')
def __init__(self, driver):
"""Initializes the HomePage with the WebDriver."""
super().__init__(driver)
self.page_path = "/" # The home page is at the root path after login
# --- Page Actions ---
def open(self, base_url: str):
"""Navigates to the home page."""
super().open(base_url, self.page_path)
def get_welcome_message(self) -> str:
"""
Gets the welcome message text from the page header.
"""
try:
return self.find_visible_element(self._WELCOME_MESSAGE).text
except:
return ""
def is_dashboard_content_visible(self) -> bool:
"""
Checks if the main dashboard content area is visible.
"""
return self.get_text(self._DASHBORAD_TEST_CASES_TITLE) == 'Test Cases'
def switch_to_profile_tab(self):
"""
Clicks the 'Profile' tab to switch to the profile view.
"""
self.click(self._PROFILE_TAB)
def click_logout_button(self):
"""Clicks the logout button."""
self.click(self._LOGOUT_BUTTON)