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 @@ -13,6 +13,9 @@ Release Notes
- Added new keyword 'Wait Until Element Is Not Visible'.
[deiga]

- Added new keyword 'Element Should Not Contain'.
[molsky]

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

Expand Down
17 changes: 17 additions & 0 deletions src/Selenium2Library/keywords/_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ def element_should_contain(self, locator, expected, message=''):
"its text was '%s'." % (locator, expected, actual)
raise AssertionError(message)

def element_should_not_contain(self, locator, expected, message=''):
"""Verifies element identified by `locator` does not contain text `expected`.

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

Key attributes for arbitrary elements are `id` and `name`. See
`Element Should Contain` for more details.
"""
self._info("Verifying element '%s' does not contain text '%s'."
% (locator, expected))
actual = self._get_text(locator)
if expected in actual:
if not message:
message = "Element '%s' should not contain text '%s' but " \
"it did." % (locator, expected)
raise AssertionError(message)

def frame_should_contain(self, locator, text, loglevel='INFO'):
"""Verifies frame identified by `locator` contains `text`.

Expand Down
6 changes: 6 additions & 0 deletions test/acceptance/keywords/content_assertions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ Element Should Contain
Run Keyword And Expect Error Element 'some_id' should have contained text 'non existing text' but its text was 'This text is inside an identified element'. Element Should Contain some_id non existing text
Run Keyword And Expect Error ValueError: Element locator 'missing_id' did not match any elements. Element Should Contain missing_id This should report missing element.

Element Should Not Contain
Element Should Not Contain some_id This text is not inside an identified element
Element Should Not Contain some_id elementypo
Run Keyword And Expect Error Element 'some_id' should not contain text 'This text is inside an identified element' but it did. Element Should Not Contain some_id This text is inside an identified element
Run Keyword And Expect Error ValueError: Element locator 'missing_id' did not match any elements. Element Should Not Contain missing_id This should report missing element.

Element Text Should Be
Element Text Should Be some_id This text is inside an identified element
Run Keyword And Expect Error The text of element 'some_id' should have been 'inside' but in fact it was 'This text is inside an identified element'. Element Text Should Be some_id inside
Expand Down