This package contains a class that serves as a base class for page object classes. The base class wraps commonly used Selenium WebDriver functionality into readable functions and gives a clean API for page objects to consume.
python setup.py develop
To use the base class, you would create a page object class that inherits from the base class found in base.py. View the API Reference for the exact calls that can be made in the API.
from marionette-wrapper.base import Base
class PageObject(Base):
#code
The sample test included with this package uses pytest to run the test. To invoke the test run the following commmand:
py.test --capture=sys tests/test_marionette_wrapper_commands.py
This reference shows the marionette-wrapper API call and it's equivalent Selenium counterpart.
This command is to launch the webpage only after checking if the URL is properly formed.
if url is not None:
regex = re.compile(
r'^(?:http|ftp)s?://'
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)'
r'+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
r'localhost|'
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
r'(?::\d+)?'
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
if regex.match(url):
self.marionette.navigate(url)
else:
raise ValueError('Url is malformed.')
This command is to click on the given element.
# marionette-wrapper
self.click_element(by, locator)
# Selenium WebDriver
self.marionette.find_element(by, locator).click()
This command is to check that an element exists in the DOM. Does not necessarily have to be visible.
# marionette-wrapper
self.wait_for_element_present(by, locator)
# Selenium WebDriver
Wait(self.marionette).until(expected.element_present(by, locator))
This command waits for an element to leave the DOM. If this does not happen before the timeout expires, an exception is thrown.
# marionette-wrapper
self.wait_for_element_not_present(by, locator)
# Selenium WebDriver
Wait(self.marionette).until(expected.element_not_present(by, locator))
This command waits for an element display itself on the page. If this does not happen before the timeout expires, an exception is thrown.
# marionette-wrapper
self.wait_for_element_displayed(by, locator)
# Selenium WebDriver
Wait(self.marionette).until(
expected.element_displayed(
Wait(self.marionette).until(
expected.element_present(by, locator))))
This command waits for an element to become invisible on the page. If this does not happen before the timeout expires, an exception is thrown.
# marionette-wrapper
self.wait_for_element_not_displayed(by, locator)
# Selenium WebDriver
Wait(self.marionette).until(
expected.element_not_displayed(
Wait(self.marionette).until(
expected.element_present(by, locator))))
This command waits for an element to become enabled. If this does not happen before the timeout expires, an exception is thrown.
# marionette-wrapper
self.wait_for_element_enabled(by, locator)
# Selenium WebDriver
Wait(self.marionette).until(
expected.element_enabled(lambda m: m.find_element(by, locator)))
This command waits for an element to become disabled. If this does not happen before the timeout expires, an exception is thrown.
# marionette-wrapper
self.wait_for_element_not_enabled(by, locator)
# Selenium WebDriver
Wait(self.marionette).until(
expected.element_not_enabled(lambda m: m.find_element(by, locator)))
This command is to return a boolean as to whether an element exists in the DOM. Does not have to be visible.
# marionette-wrapper
self.is_element_present(by, locator)
# Selenium WebDriver
try:
self.marionette.find_element(by, locator)
return True
except NoSuchElementException:
return False
This command is to return a boolean as to whether an element is present and visible on the page.
# marionette-wrapper
self.is_element_displayed(by, locator)
# Selenium WebDriver
try:
return self.marionette.find_element(by, locator).is_displayed()
except NoSuchElementException:
return False