-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_page.py
55 lines (42 loc) · 1.72 KB
/
base_page.py
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
48
49
50
51
52
53
54
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