From 087e88c553ac7f07b61c40d54d89aa76338a9d02 Mon Sep 17 00:00:00 2001 From: Steve Jefferies Date: Fri, 8 Feb 2013 14:56:13 +0000 Subject: [PATCH] Support for verifying textarea element text Addresses the issue described in #167. --- src/Selenium2Library/keywords/_formelement.py | 38 +++++++++++++++++++ .../locators/elementfinder.py | 2 + 2 files changed, 40 insertions(+) diff --git a/src/Selenium2Library/keywords/_formelement.py b/src/Selenium2Library/keywords/_formelement.py index ff9c26b89..a710c8ccf 100644 --- a/src/Selenium2Library/keywords/_formelement.py +++ b/src/Selenium2Library/keywords/_formelement.py @@ -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): diff --git a/src/Selenium2Library/locators/elementfinder.py b/src/Selenium2Library/locators/elementfinder.py index 821d183f8..1db256242 100644 --- a/src/Selenium2Library/locators/elementfinder.py +++ b/src/Selenium2Library/locators/elementfinder.py @@ -127,6 +127,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):