diff --git a/CHANGES.rst b/CHANGES.rst index 3bfa40f43..f2c8e78be 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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] diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index a91edfbf6..9a4543229 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -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`. diff --git a/test/acceptance/keywords/content_assertions.txt b/test/acceptance/keywords/content_assertions.txt index 90517d3f6..26c0e8ffd 100644 --- a/test/acceptance/keywords/content_assertions.txt +++ b/test/acceptance/keywords/content_assertions.txt @@ -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