Skip to content

Commit

Permalink
added base implementation for base_page.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy.berezovskyi committed Oct 14, 2024
1 parent 704e4ab commit d4620ff
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
addopts = "-rA -v --env=dev --browser-type=chromium --listeners=events --capture=no -p no:cacheprovider --html=../reports/test_report.html"
addopts = "-rA -v --env=dev --browser-type=chromium --listeners=events --capture=no -p no:cacheprovider --html=../reports/test_report.html --self-contained-html"
#asyncio_mode = "auto"
markers = [
{ name = "smoke", description = "run smoke tests" },
Expand Down
45 changes: 45 additions & 0 deletions src/base_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from playwright.sync_api import Page
from utils.logger import log


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

@log()
def navigate_to(self, url: str):
"""Navigate to a specified URL."""
self.page.goto(url)

@log()
def click(self, selector: str):
"""Click an element by selector."""
self.wait_for_selector(selector)
self.page.locator(selector).click()

@log()
def fill(self, selector: str, value: str):
"""Fill an input field with a specified value."""
self.wait_for_selector(selector)
self.page.locator(selector).fill(value)

@log()
def wait_for_selector(self, selector: str, timeout: int = 10000):
"""Wait for a specific selector to be visible."""
self.page.wait_for_selector(selector, timeout=timeout)

@log()
def wait_for_clickable(self, selector: str, timeout: int = 10000):
"""Wait for a specific selector to be clickable."""
self.page.wait_for_selector(selector, state="visible", timeout=timeout)
self.page.locator(selector).wait_for(state="attached", timeout=timeout)

@log()
def is_visible(self, selector: str) -> bool:
"""Assert that an element is visible on the page."""
return self.page.is_visible(selector)

@log()
def close(self):
"""Close the page."""
self.page.close()

0 comments on commit d4620ff

Please sign in to comment.