Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Release Notes
- Added new keyword 'Wait Until Page Does Not Contain Element'.
[molsky]

- Added new keywords 'Wait Until Element Contains' and 'Wait Until Element Does Not Contain'
[molsky]

- Added new locator strategy, scLocator, for finding SmartClient and SmartGWT elements.
[IlfirinPL]

Expand Down
46 changes: 46 additions & 0 deletions src/Selenium2Library/keywords/_waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,52 @@ def check_enabled():

self._wait_until_no_error(timeout, check_enabled)

def wait_until_element_contains(self, locator, text, timeout=None, error=None):
"""Waits until given element contains `text`.

Fails if `timeout` expires before the text appears on given element. See
`introduction` for more information about `timeout` and its
default value.

`error` can be used to override the default error message.

See also `Wait Until Page Contains`, `Wait Until Page Contains Element`, `Wait For Condition`,
`Wait Until Element Is Visible` and BuiltIn keyword `Wait Until
Keyword Succeeds`.
"""
element = self._element_find(locator, True, True)
def check_text():
actual = element.text
if text in actual:
return
else:
return error or "Text '%s' did not appear in %s to element '%s'. " \
"Its text was '%s'." % (text, self._format_timeout(timeout), locator, actual)
self._wait_until_no_error(timeout, check_text)


def wait_until_element_does_not_contain(self, locator, text, timeout=None, error=None):
"""Waits until given element does not contain `text`.

Fails if `timeout` expires before the text disappears from given element. See
`introduction` for more information about `timeout` and its
default value.

`error` can be used to override the default error message.

See also `Wait Until Page Contains`, `Wait Until Page Contains Element`, `Wait For Condition`,
`Wait Until Element Is Visible` and BuiltIn keyword `Wait Until
Keyword Succeeds`.
"""
element = self._element_find(locator, True, True)
def check_text():
actual = element.text
if not text in actual:
return
else:
return error or "Text '%s' did not disappear in %s from element '%s'." % (text, self._format_timeout(timeout), locator)
self._wait_until_no_error(timeout, check_text)

# Private

def _wait_until(self, timeout, error, function, *args):
Expand Down
13 changes: 13 additions & 0 deletions test/acceptance/keywords/waiting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ Wait Until Element Is Enabled
Run Keyword And Expect Error Element locator 'id=invalid' did not match any elements after 100 milliseconds Wait Until Element Is Enabled id=invalid 0.1
Run Keyword And Expect Error User error message Wait Until Element Is Enabled id=invalid 0.1 User error message

Wait Until Element Contains
Run Keyword And Expect Error Text 'New' did not appear in 100 milliseconds to element 'id=content'. Its text was 'This is content'. Wait Until Element Contains id=content New 0.1
Wait Until Element Contains content New Content 2 s
Wait Until Element Contains content New 2 s
Run Keyword And Expect Error User error message Wait Until Element Contains content Error 0.1 User error message
Run Keyword And Expect Error ValueError: Element locator 'id=invalid' did not match any elements. Wait Until Element Contains id=invalid content 0.1

Wait Until Element Does Not Contain
Run Keyword And Expect Error Text 'This is' did not disappear in 100 milliseconds from element 'id=content'. Wait Until Element Does Not Contain id=content This is 0.1
Wait Until Element Does Not Contain content This is 2 s
Wait Until Element Does Not Contain id=content content 2 s
Run Keyword And Expect Error User error message Wait Until Element Does Not Contain content New Content 0.1 User error message