Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create BasePage class and base actions to interact with Pages #1

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 55 additions & 0 deletions src/pageobjects/base_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from enum import Enum
from typing import Tuple

from appium.webdriver import WebElement
from selenium.common import ElementNotVisibleException, TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait

Locator = Tuple[By, str]


class WaitType(Enum):
DEFAULT = 20
SHORT = 5
LONG = 60
FLUENT = 10


class BasePage:

def __init__(self, driver):
self.driver = driver
self._wait = WebDriverWait(driver, WaitType.DEFAULT.value)
self._short_wait = WebDriverWait(driver, WaitType.SHORT.value)
self._long_wait = WebDriverWait(driver, WaitType.LONG.value)
self._fluent_wait = WebDriverWait(driver, WaitType.FLUENT.value, poll_frequency=1,
ignored_exceptions=[ElementNotVisibleException])

def wait(self, locator: Locator, waiter: WebDriverWait = None) -> WebElement:
if waiter is None:
waiter = self._wait
try:
return waiter.until(ec.presence_of_element_located(locator))
except TimeoutException:
raise TimeoutException(f"Element {locator} not found after {waiter._timeout} seconds")

def find(self, locator: Locator):
self.driver.find_element(*locator)

def click(self, locator: Locator):
element = self.wait(locator)
element.click()

def set(self, locator: Locator, text: str):
element = self.wait(locator)
element.clear()
element.send_keys(text)

def get_text(self, locator: Locator):
element = self.wait(locator)
return element.text

def get_title(self):
return self.driver.title
Empty file added src/utils/logger.py
Empty file.