-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbase_page.py
More file actions
41 lines (30 loc) · 1.23 KB
/
base_page.py
File metadata and controls
41 lines (30 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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)