Skip to content

Commit ac83046

Browse files
committed
Merge pull request #373 from molsky/master
Add 'Element Should Not Contain' keyword
2 parents 348a143 + 59d9565 commit ac83046

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Release Notes
1313
- Added new keyword 'Wait Until Element Is Not Visible'.
1414
[deiga]
1515

16+
- Added new keyword 'Element Should Not Contain'.
17+
[molsky]
18+
1619
- Added new locator strategy, scLocator, for finding SmartClient and SmartGWT elements.
1720
[IlfirinPL]
1821

src/Selenium2Library/keywords/_element.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ def element_should_contain(self, locator, expected, message=''):
5454
"its text was '%s'." % (locator, expected, actual)
5555
raise AssertionError(message)
5656

57+
def element_should_not_contain(self, locator, expected, message=''):
58+
"""Verifies element identified by `locator` does not contain text `expected`.
59+
60+
`message` can be used to override the default error message.
61+
62+
Key attributes for arbitrary elements are `id` and `name`. See
63+
`Element Should Contain` for more details.
64+
"""
65+
self._info("Verifying element '%s' does not contain text '%s'."
66+
% (locator, expected))
67+
actual = self._get_text(locator)
68+
if expected in actual:
69+
if not message:
70+
message = "Element '%s' should not contain text '%s' but " \
71+
"it did." % (locator, expected)
72+
raise AssertionError(message)
73+
5774
def frame_should_contain(self, locator, text, loglevel='INFO'):
5875
"""Verifies frame identified by `locator` contains `text`.
5976

test/acceptance/keywords/content_assertions.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ Element Should Contain
8383
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
8484
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.
8585

86+
Element Should Not Contain
87+
Element Should Not Contain some_id This text is not inside an identified element
88+
Element Should Not Contain some_id elementypo
89+
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
90+
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.
91+
8692
Element Text Should Be
8793
Element Text Should Be some_id This text is inside an identified element
8894
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

0 commit comments

Comments
 (0)