Skip to content

Commit

Permalink
Merge pull request #373 from molsky/master
Browse files Browse the repository at this point in the history
Add 'Element Should Not Contain' keyword
  • Loading branch information
zephraph committed May 11, 2015
2 parents 348a143 + 59d9565 commit ac83046
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
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
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
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

0 comments on commit ac83046

Please sign in to comment.