Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Element Should Not Contain' keyword #373

Merged
merged 13 commits into from May 11, 2015
Merged
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