Spaces:
Running
Running
File size: 1,708 Bytes
60b6623 4f2f855 60b6623 bbce707 60b6623 |
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 42 43 44 45 46 47 |
from playwright.sync_api import Page, expect
import time
class BasePage:
"""Base page object with common functionality"""
def __init__(self, page: Page):
self.page = page
self.base_url = "http://localhost:7860"
def navigate_to(self, path: str = ""):
"""Navigate to the page"""
self.page.goto(f"{self.base_url}{path}")
self.page.wait_for_load_state("networkidle")
def wait_for_element(self, selector: str, timeout: int = 10000):
"""Wait for element to be visible"""
self.page.wait_for_selector(selector, timeout=timeout)
def click_element(self, selector: str):
"""Click element with auto-wait"""
self.page.click(selector)
def fill_input(self, selector: str, value: str):
"""Fill input field with auto-wait"""
self.page.fill(selector, value)
def expect_element_visible(self, selector: str):
"""Expect element to be visible"""
expect(self.page.locator(selector)).to_be_visible()
def expect_element_not_visible(self, selector: str):
"""Expect element to not be visible"""
expect(self.page.locator(selector)).not_to_be_visible()
def expect_url_contains(self, url_part: str):
"""Expect URL to contain specific part"""
expect(self.page).to_have_url(f".*{url_part}.*")
def get_text(self, selector: str) -> str:
"""Get text content of element"""
return self.page.locator(selector).text_content()
def upload_file(self, file_input_selector: str, file_path: str):
"""Upload file using file input"""
self.page.set_input_files(file_input_selector, file_path)
|