Skip to content

Commit

Permalink
Support for verifying textarea element text
Browse files Browse the repository at this point in the history
Addresses the issue described in robotframework#167.
  • Loading branch information
stevejefferies authored and emanlove committed Sep 1, 2013
1 parent 54f3a53 commit 5eafecf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Selenium2Library/keywords/_formelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,44 @@ def textfield_value_should_be(self, locator, expected, message=''):
raise AssertionError(message)
self._info("Content of text field '%s' is '%s'." % (locator, expected))

def textarea_should_contain(self, locator, expected, message=''):
"""Verifies text area identified by `locator` contains text `expected`.
`message` can be used to override default error message.
Key attributes for text areas are `id` and `name`. See `introduction`
for details about locating elements.
"""
actual = self._get_value(locator, 'text area')
if actual is not None:
if not expected in actual:
if not message:
message = "Text field '%s' should have contained text '%s' "\
"but it contained '%s'" % (locator, expected, actual)
raise AssertionError(message)
else:
raise ValueError("Element locator '" + locator + "' did not match any elements.")
self._info("Text area '%s' contains text '%s'." % (locator, expected))

def textarea_value_should_be(self, locator, expected, message=''):
"""Verifies the value in text area identified by `locator` is exactly `expected`.
`message` can be used to override default error message.
Key attributes for text areas are `id` and `name`. See `introduction`
for details about locating elements.
"""
actual = self._get_value(locator, 'text area')
if actual is not None:
if expected!=actual:
if not message:
message = "Text field '%s' should have contained text '%s' "\
"but it contained '%s'" % (locator, expected, actual)
raise AssertionError(message)
else:
raise ValueError("Element locator '" + locator + "' did not match any elements.")
self._info("Content of text area '%s' is '%s'." % (locator, expected))

# Public, buttons

def click_button(self, locator):
Expand Down
2 changes: 2 additions & 0 deletions src/Selenium2Library/locators/elementfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def _get_tag_and_constraints(self, tag):
elif tag == 'file upload':
tag = 'input'
constraints['type'] = 'file'
elif tag == 'text area':
tag = 'textarea'
return tag, constraints

def _element_matches(self, element, tag, constraints):
Expand Down

0 comments on commit 5eafecf

Please sign in to comment.