Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/pages/base_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# BasePage for Playwright reusable actions

from playwright.sync_api import Page, expect


class BasePage:
"""
BasePage provides common Playwright actions
that can be reused across all Page Objects.
"""

def __init__(self, page: Page):
self.page = page

def open(self, url: str) -> None:
"""Navigate to a given URL"""
self.page.goto(url)

def click(self, locator: str) -> None:
"""Click on a web element"""
self.page.locator(locator).click()

def fill(self, locator: str, value: str) -> None:
"""Fill input field with value"""
self.page.locator(locator).fill(value)

def get_text(self, locator: str) -> str:
"""Return text of an element"""
return self.page.locator(locator).inner_text()

def is_visible(self, locator: str) -> bool:
"""Check if element is visible"""
return self.page.locator(locator).is_visible()

def wait_for(self, locator: str) -> None:
"""Wait until element is visible"""
self.page.locator(locator).wait_for()

def assert_text(self, locator: str, expected_text: str) -> None:
"""Assert exact text of an element"""
expect(self.page.locator(locator)).to_have_text(expected_text)