Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

76 lines (54 sloc) 2.451 kB
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from unittestzero import Assert
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException, ElementNotVisibleException
class Page(object):
def __init__(self, testsetup, **kwargs):
self.testsetup = testsetup
self.base_url = testsetup.base_url
self.selenium = testsetup.selenium
self.timeout = testsetup.timeout
self._selenium_root = hasattr(self, '_root_element') and self._root_element or self.selenium
for key, value in kwargs.items():
setattr(self, key, value)
@property
def is_the_current_page(self):
if self._page_title:
WebDriverWait(self.selenium, self.timeout).until(lambda s: s.title)
Assert.contains(self._page_title, self.selenium.title,
'Expected page title does not match actual page title.')
return True
def is_element_visible(self, *locator):
self.selenium.implicitly_wait(0)
try:
return self._selenium_root.find_element(*locator).is_displayed()
except (NoSuchElementException, ElementNotVisibleException):
return False
finally:
self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)
def get_url_current_page(self):
return self.selenium.current_url
def get_relative_path(self, url):
self.selenium.get(u'%s%s' % (self.base_url, url))
def find_element(self, *locator):
return self._selenium_root.find_element(*locator)
def find_elements(self, *locator):
return self._selenium_root.find_elements(*locator)
def type_in_element(self, locator, text):
"""
Type a string into an element.
This method clears the element first then types the string via send_keys.
Arguments:
locator -- a locator for the element
text -- the string to type via send_keys
"""
text_fld = self._selenium_root.find_element(*locator)
text_fld.clear()
text_fld.send_keys(text)
class PageRegion(Page):
def __init__(self, testsetup, element):
self._root_element = element
Page.__init__(self, testsetup)
Jump to Line
Something went wrong with that request. Please try again.