Skip to content

Commit

Permalink
attr match + attr & element get methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jari committed Sep 23, 2015
1 parent 030c169 commit a7f5676
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -29,6 +29,9 @@ nosetests.xml
# Translations
*.mo

# PyCharm
.idea

# Mr Developer
.mr.developer.cfg
.project
Expand Down
18 changes: 18 additions & 0 deletions src/AppiumLibrary/keywords/_element.py
Expand Up @@ -160,6 +160,24 @@ def element_name_should_be(self, locator, expected):
"but it is '%s'." % (locator, expected, element.get_attribute('name')))
self._info("Element '%s' name is '%s' " % (locator, expected))

def element_attribute_should_be(self, locator, attr_name, expected):
elements = self._element_find(locator, False, True)
if len(elements) > 1:
self._info("CAUTION: '%s' matched %s elements - using the first element only" % (locator, len(elements)))
if expected != elements[0].get_attribute(attr_name):
raise AssertionError("Element '%s' attribute '%s' should have been '%s' "
"but it was '%s'." % (locator, attr_name, expected, element.get_attribute('name')))
self._info("Element '%s' attribute '%s' is '%s' " % (locator, attr_name, expected))

def get_element_attribute(self, locator, attr_name):
elements = self._element_find(locator, False, True)
if len(elements) > 1:
self._info("CAUTION: '%s' matched %s elements - using the first element only" % (locator, len(elements)))
return elements.get_attribute(attr_name)

def get_elements(self, locator, first_element_only=False, fail_on_error=True):
return self._element_find(locator, first_element_only, fail_on_error)


# Private

Expand Down

0 comments on commit a7f5676

Please sign in to comment.