Skip to content

Commit

Permalink
Merge pull request #94 from neetjn/0.2.1
Browse files Browse the repository at this point in the history
0.2.1
  • Loading branch information
neetjn committed Apr 11, 2018
2 parents 57a9ad8 + 45db29f commit 0083fcb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
# built documents.
#
# The short X.Y version.
version = u'0.2.0'
version = u'0.2.1'
# The full version, including alpha/beta/rc tags.
release = u'0.2.0'
release = u'0.2.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ When a controller is instantiated, the constructor automatically binds the follo
Adding Services
===============

Services are defined in more detail `here <https://google.com>`_.
Services are defined in more detail `here <http://py-component-controller.readthedocs.io/en/latest/service.html>`_.

To add a new service to your controller, refer to the api method **add_service**:

Expand Down
35 changes: 31 additions & 4 deletions pyscc/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from pyscc.resource import Resource


ELEMENTS_STALE_WAIT_TIME = 3


# pylint: disable=too-many-public-methods
class Element(Resource):
"""
Expand Down Expand Up @@ -440,6 +443,10 @@ def __find_elements(self):
return self.controller.browser.find_elements_by_css_selector(self.selector) \
or self.controller.browser.find_elements_by_xpath(self.selector)

def __wait_elements_not_stale(self, timeout):
# pylint: disable=line-too-long
self.controller.wait(timeout, condition=lambda: [element.text for element in self.get()])

def fmt(self, **kwargs):
"""
Used to format selectors.
Expand All @@ -465,14 +472,19 @@ def count(self):
"""
return len(self.get())

def text(self, raw=False):
def text(self, raw=False, check_stale_element=False):
"""
Get list of element text values.
:param raw: Extract inner html from element.
:type raw: bool
:param check_stale_element: Ensure retrieved WebElement instances are finished mounting.
:type check_stale_element: bool
:return: [string, ...], None
"""
if check_stale_element:
# wait in the event element list is actively loading
self.__wait_elements_not_stale(ELEMENTS_STALE_WAIT_TIME)
found = self.get()
if found:
collection = []
Expand All @@ -485,22 +497,32 @@ def text(self, raw=False):
return collection
return []

def value(self):
def value(self, check_stale_element=False):
"""
Get list of input element values.
:param check_stale_element: Ensure retrieved WebElement instances are finished mounting.
:type check_stale_element: bool
:return: [string, ...], None
"""
if check_stale_element:
# wait in the event element list is actively loading
self.__wait_elements_not_stale(ELEMENTS_STALE_WAIT_TIME)
return [self.controller.js.get_value(element) for element in self.get()]

def get_attribute(self, attribute):
def get_attribute(self, attribute, check_stale_element=False):
"""
Used to fetch list of elements attributes.
:param attribute: Attribute of elements to target.
:type attribute: string
:param check_stale_element: Ensure retrieved WebElement instances are finished mounting.
:type check_stale_element: bool
:return: [(None, bool, int, float, string), ...]
"""
if check_stale_element:
# wait in the event element list is actively loading
self.__wait_elements_not_stale(ELEMENTS_STALE_WAIT_TIME)
return [self.controller.js.get_attribute(element, attribute) for element in self.get()]

def set_attribute(self, attribute, value):
Expand All @@ -517,14 +539,19 @@ def set_attribute(self, attribute, value):
self.controller.js.set_attribute(element, attribute, value)
return self

def get_property(self, prop):
def get_property(self, prop, check_stale_element=False):
"""
Used to fetch list of elements properties.
:param prop: Property of elements to target.
:type prop: string
:param check_stale_element: Ensure retrieved WebElement instances are finished mounting.
:type check_stale_element: bool
:return: None, bool, int, float, string
"""
if check_stale_element:
# wait in the event element list is actively loading
self.__wait_elements_not_stale(ELEMENTS_STALE_WAIT_TIME)
return [self.controller.js.get_property(element, prop) for element in self.get()]

def set_property(self, prop, value):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
setup(
name='pyscc',
description='py-component-controller is an opinionated framework for structuring selenium test suites. This project depends on the pyselenium-js project.',
version='0.2.0',
version='0.2.1',
url='https://neetjn.github.io/py-component-controller/',
author='John Nolette',
author_email='john@neetgroup.net',
Expand Down
3 changes: 3 additions & 0 deletions tests/test_component_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def test_elements_wrapper_text(self):
"""test elements wrapper text aggregation"""
self.app.wait(timeout=1) # wait for transitions
self.assertEqual(len(self.tasks.text()), 3)
self.assertEqual(len(self.tasks.text(check_stale_element=True)), 3)
for task in self.tasks.text():
self.assertIn('2017', task)
for task in self.tasks.text(raw=True):
Expand All @@ -213,6 +214,7 @@ def test_elements_wrapper_attributes(self):
self.assertEqual(len(attributes), 3)
for attr in attributes:
self.assertEqual(attr, 'barfoo')
self.assertEqual(len(self.tasks.get_attribute('foobar', check_stale_element=True)), 3)

def test_elements_wrapper_properties(self):
"""test elements wrapper property aggregation and specification"""
Expand All @@ -223,3 +225,4 @@ def test_elements_wrapper_properties(self):
self.assertEqual(len(properties), 3)
for prop in properties:
self.assertEqual(prop, 'barfoo')
self.assertEqual(len(self.tasks.get_property('foobar', check_stale_element=True)), 3)

0 comments on commit 0083fcb

Please sign in to comment.