2017-08-28 10:02:20 +00:00
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
from selenium.common.exceptions import NoSuchElementException, TimeoutException
|
|
|
|
from selenium.webdriver.support.wait import WebDriverWait
|
|
|
|
from selenium.webdriver.support import expected_conditions
|
2017-08-31 13:39:41 +00:00
|
|
|
from appium.webdriver.common.touch_action import TouchAction
|
2017-08-28 10:02:20 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
class BaseElement(object):
|
|
|
|
|
|
|
|
class Locator(object):
|
|
|
|
|
|
|
|
def __init__(self, by, value):
|
|
|
|
self.by = by
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def xpath_selector(locator, value):
|
|
|
|
return locator(By.XPATH, value)
|
|
|
|
|
|
|
|
def __str__(self, *args, **kwargs):
|
|
|
|
return "%s:%s" % (self.by, self.value)
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
self.driver = driver
|
|
|
|
self.locator = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
return self.__class__.__name__
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def find_element(self):
|
2017-08-31 13:39:41 +00:00
|
|
|
return self.driver.find_element(self.locator.by, self.locator.value)
|
2017-08-28 10:02:20 +00:00
|
|
|
|
2017-08-31 13:39:41 +00:00
|
|
|
def wait_for_element(self, seconds=10):
|
2017-08-28 10:02:20 +00:00
|
|
|
return WebDriverWait(self.driver, seconds)\
|
|
|
|
.until(expected_conditions.presence_of_element_located((self.locator.by, self.locator.value)))
|
|
|
|
|
2017-08-31 13:39:41 +00:00
|
|
|
def scroll_to_element(self):
|
|
|
|
for x in range(10):
|
|
|
|
action = TouchAction(self.driver)
|
|
|
|
action.press(x=0, y=1000).move_to(x=200, y=-1000).release().perform()
|
|
|
|
try:
|
|
|
|
self.find_element()
|
|
|
|
break
|
|
|
|
except NoSuchElementException:
|
|
|
|
pass
|
|
|
|
|
2017-08-28 10:02:20 +00:00
|
|
|
|
|
|
|
class BaseEditBox(BaseElement):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(BaseEditBox, self).__init__(driver)
|
|
|
|
self.driver = driver
|
|
|
|
|
|
|
|
def send_keys(self, value):
|
|
|
|
self.find_element().send_keys(value)
|
|
|
|
|
|
|
|
|
|
|
|
class BaseText(BaseElement):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(BaseText, self).__init__(driver)
|
|
|
|
self.driver = driver
|
|
|
|
|
|
|
|
@property
|
|
|
|
def text(self):
|
|
|
|
return self.find_element().text
|
|
|
|
|
|
|
|
|
|
|
|
class BaseButton(BaseElement):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(BaseButton, self).__init__(driver)
|
|
|
|
self.driver = driver
|
|
|
|
|
|
|
|
def click(self):
|
|
|
|
self.find_element().click()
|
|
|
|
return self.navigate()
|