Skip to content

Commit 087e88c

Browse files
Support for verifying textarea element text
Addresses the issue described in robotframework#167.
1 parent 406f6d1 commit 087e88c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Selenium2Library/keywords/_formelement.py

+38
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,44 @@ def textfield_value_should_be(self, locator, expected, message=''):
253253
raise AssertionError(message)
254254
self._info("Content of text field '%s' is '%s'." % (locator, expected))
255255

256+
def textarea_should_contain(self, locator, expected, message=''):
257+
"""Verifies text area identified by `locator` contains text `expected`.
258+
259+
`message` can be used to override default error message.
260+
261+
Key attributes for text areas are `id` and `name`. See `introduction`
262+
for details about locating elements.
263+
"""
264+
actual = self._get_value(locator, 'text area')
265+
if actual is not None:
266+
if not expected in actual:
267+
if not message:
268+
message = "Text field '%s' should have contained text '%s' "\
269+
"but it contained '%s'" % (locator, expected, actual)
270+
raise AssertionError(message)
271+
else:
272+
raise ValueError("Element locator '" + locator + "' did not match any elements.")
273+
self._info("Text area '%s' contains text '%s'." % (locator, expected))
274+
275+
def textarea_value_should_be(self, locator, expected, message=''):
276+
"""Verifies the value in text area identified by `locator` is exactly `expected`.
277+
278+
`message` can be used to override default error message.
279+
280+
Key attributes for text areas are `id` and `name`. See `introduction`
281+
for details about locating elements.
282+
"""
283+
actual = self._get_value(locator, 'text area')
284+
if actual is not None:
285+
if expected!=actual:
286+
if not message:
287+
message = "Text field '%s' should have contained text '%s' "\
288+
"but it contained '%s'" % (locator, expected, actual)
289+
raise AssertionError(message)
290+
else:
291+
raise ValueError("Element locator '" + locator + "' did not match any elements.")
292+
self._info("Content of text area '%s' is '%s'." % (locator, expected))
293+
256294
# Public, buttons
257295

258296
def click_button(self, locator):

src/Selenium2Library/locators/elementfinder.py

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def _get_tag_and_constraints(self, tag):
127127
elif tag == 'file upload':
128128
tag = 'input'
129129
constraints['type'] = 'file'
130+
elif tag == 'text area':
131+
tag = 'textarea'
130132
return tag, constraints
131133

132134
def _element_matches(self, element, tag, constraints):

0 commit comments

Comments
 (0)