From d24233649c5901b62bdb09cabe3503e07804216f Mon Sep 17 00:00:00 2001 From: molsky Date: Fri, 10 Apr 2015 16:28:33 +0300 Subject: [PATCH 01/11] Add 'Element Should Not Contain' -keyword --- src/Selenium2Library/keywords/_element.py | 17 +++++++++++++++++ test/acceptance/keywords/content_assertions.txt | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index a91edfbf6..22a03f07d 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, text, message=''): + """Verifies element identified by `locator` does not contain text `text`. + + `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, text)) + actual = self._get_text(locator) + if text in actual: + if message: + message = "Element '%s' should have not contained text '%s' but " \ + "it did." % (locator, text) + 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..5d418785a 100644 --- a/test/acceptance/keywords/content_assertions.txt +++ b/test/acceptance/keywords/content_assertions.txt @@ -83,6 +83,11 @@ 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 Contain some_id This text is not inside an identified element + Run Keyword And Expect Error Element 'some_id' should have not contained 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 From edfd7126a8bbbf2e5ae046b3761c438726174493 Mon Sep 17 00:00:00 2001 From: molsky Date: Fri, 10 Apr 2015 16:40:35 +0300 Subject: [PATCH 02/11] Fix typo in keyword's test script. Fix huge error in keyword's code. --- src/Selenium2Library/keywords/_element.py | 2 +- test/acceptance/keywords/content_assertions.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index 22a03f07d..6e140307c 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -66,7 +66,7 @@ def element_should_not_contain(self, locator, text, message=''): % (locator, text)) actual = self._get_text(locator) if text in actual: - if message: + if not message: message = "Element '%s' should have not contained text '%s' but " \ "it did." % (locator, text) raise AssertionError(message) diff --git a/test/acceptance/keywords/content_assertions.txt b/test/acceptance/keywords/content_assertions.txt index 5d418785a..3ed6485e6 100644 --- a/test/acceptance/keywords/content_assertions.txt +++ b/test/acceptance/keywords/content_assertions.txt @@ -84,7 +84,7 @@ Element Should Contain 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 Contain some_id This text is not inside an identified element + Element Should Not Contain some_id This text is not inside an identified element Run Keyword And Expect Error Element 'some_id' should have not contained 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. From df22a83b8a679a1a262498f8061f899fd9bf116c Mon Sep 17 00:00:00 2001 From: molsky Date: Fri, 10 Apr 2015 16:57:36 +0300 Subject: [PATCH 03/11] Fix grammar --- src/Selenium2Library/keywords/_element.py | 2 +- test/acceptance/keywords/content_assertions.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index 6e140307c..b03002df5 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -67,7 +67,7 @@ def element_should_not_contain(self, locator, text, message=''): actual = self._get_text(locator) if text in actual: if not message: - message = "Element '%s' should have not contained text '%s' but " \ + message = "Element '%s' should not contain text '%s' but " \ "it did." % (locator, text) raise AssertionError(message) diff --git a/test/acceptance/keywords/content_assertions.txt b/test/acceptance/keywords/content_assertions.txt index 3ed6485e6..e0494dfb3 100644 --- a/test/acceptance/keywords/content_assertions.txt +++ b/test/acceptance/keywords/content_assertions.txt @@ -85,7 +85,7 @@ Element Should Contain Element Should Not Contain Element Should Not Contain some_id This text is not inside an identified element - Run Keyword And Expect Error Element 'some_id' should have not contained 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 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 From ea8d3efd13279538d5202782f0d9117601ddc6c3 Mon Sep 17 00:00:00 2001 From: molsky Date: Fri, 10 Apr 2015 17:02:36 +0300 Subject: [PATCH 04/11] Add another Keyword test. --- test/acceptance/keywords/content_assertions.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/acceptance/keywords/content_assertions.txt b/test/acceptance/keywords/content_assertions.txt index e0494dfb3..26c0e8ffd 100644 --- a/test/acceptance/keywords/content_assertions.txt +++ b/test/acceptance/keywords/content_assertions.txt @@ -85,6 +85,7 @@ Element Should Contain 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. From 9e25f6b081aa910e4941c6cabc29eee139fcd28d Mon Sep 17 00:00:00 2001 From: molsky Date: Sat, 11 Apr 2015 14:53:30 +0300 Subject: [PATCH 05/11] Change 'text' variable name back to original one (same naming logic as in Element Should Contain -keyword) --- src/Selenium2Library/keywords/_element.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index b03002df5..9a4543229 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -54,8 +54,8 @@ 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, text, message=''): - """Verifies element identified by `locator` does not contain text `text`. + 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. @@ -63,12 +63,12 @@ def element_should_not_contain(self, locator, text, message=''): `Element Should Contain` for more details. """ self._info("Verifying element '%s' does not contain text '%s'." - % (locator, text)) + % (locator, expected)) actual = self._get_text(locator) - if text in actual: + if expected in actual: if not message: message = "Element '%s' should not contain text '%s' but " \ - "it did." % (locator, text) + "it did." % (locator, expected) raise AssertionError(message) def frame_should_contain(self, locator, text, loglevel='INFO'): From bb59fb1f69a998062d10684a7ae3ff3ba298909a Mon Sep 17 00:00:00 2001 From: molsky Date: Fri, 10 Apr 2015 16:28:33 +0300 Subject: [PATCH 06/11] Add 'Element Should Not Contain' -keyword --- src/Selenium2Library/keywords/_element.py | 17 +++++++++++++++++ test/acceptance/keywords/content_assertions.txt | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index a91edfbf6..22a03f07d 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, text, message=''): + """Verifies element identified by `locator` does not contain text `text`. + + `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, text)) + actual = self._get_text(locator) + if text in actual: + if message: + message = "Element '%s' should have not contained text '%s' but " \ + "it did." % (locator, text) + 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..5d418785a 100644 --- a/test/acceptance/keywords/content_assertions.txt +++ b/test/acceptance/keywords/content_assertions.txt @@ -83,6 +83,11 @@ 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 Contain some_id This text is not inside an identified element + Run Keyword And Expect Error Element 'some_id' should have not contained 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 From 1b5e3dc3d05a9162d7021488feab5cb7f5625504 Mon Sep 17 00:00:00 2001 From: molsky Date: Fri, 10 Apr 2015 16:40:35 +0300 Subject: [PATCH 07/11] Fix typo in keyword's test script. Fix huge error in keyword's code. --- src/Selenium2Library/keywords/_element.py | 2 +- test/acceptance/keywords/content_assertions.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index 22a03f07d..6e140307c 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -66,7 +66,7 @@ def element_should_not_contain(self, locator, text, message=''): % (locator, text)) actual = self._get_text(locator) if text in actual: - if message: + if not message: message = "Element '%s' should have not contained text '%s' but " \ "it did." % (locator, text) raise AssertionError(message) diff --git a/test/acceptance/keywords/content_assertions.txt b/test/acceptance/keywords/content_assertions.txt index 5d418785a..3ed6485e6 100644 --- a/test/acceptance/keywords/content_assertions.txt +++ b/test/acceptance/keywords/content_assertions.txt @@ -84,7 +84,7 @@ Element Should Contain 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 Contain some_id This text is not inside an identified element + Element Should Not Contain some_id This text is not inside an identified element Run Keyword And Expect Error Element 'some_id' should have not contained 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. From 609bd95b567a830da5bd478fdee78c35954a4904 Mon Sep 17 00:00:00 2001 From: molsky Date: Fri, 10 Apr 2015 16:57:36 +0300 Subject: [PATCH 08/11] Fix grammar --- src/Selenium2Library/keywords/_element.py | 2 +- test/acceptance/keywords/content_assertions.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index 6e140307c..b03002df5 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -67,7 +67,7 @@ def element_should_not_contain(self, locator, text, message=''): actual = self._get_text(locator) if text in actual: if not message: - message = "Element '%s' should have not contained text '%s' but " \ + message = "Element '%s' should not contain text '%s' but " \ "it did." % (locator, text) raise AssertionError(message) diff --git a/test/acceptance/keywords/content_assertions.txt b/test/acceptance/keywords/content_assertions.txt index 3ed6485e6..e0494dfb3 100644 --- a/test/acceptance/keywords/content_assertions.txt +++ b/test/acceptance/keywords/content_assertions.txt @@ -85,7 +85,7 @@ Element Should Contain Element Should Not Contain Element Should Not Contain some_id This text is not inside an identified element - Run Keyword And Expect Error Element 'some_id' should have not contained 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 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 From 0683989580e9f08797a21c116ba125e3758930a1 Mon Sep 17 00:00:00 2001 From: molsky Date: Fri, 10 Apr 2015 17:02:36 +0300 Subject: [PATCH 09/11] Add another Keyword test. --- test/acceptance/keywords/content_assertions.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/acceptance/keywords/content_assertions.txt b/test/acceptance/keywords/content_assertions.txt index e0494dfb3..26c0e8ffd 100644 --- a/test/acceptance/keywords/content_assertions.txt +++ b/test/acceptance/keywords/content_assertions.txt @@ -85,6 +85,7 @@ Element Should Contain 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. From aec1296e818cafa527b3e893cbd304bd14bd6a32 Mon Sep 17 00:00:00 2001 From: molsky Date: Sat, 11 Apr 2015 14:53:30 +0300 Subject: [PATCH 10/11] Change 'text' variable name back to original one (same naming logic as in Element Should Contain -keyword) --- src/Selenium2Library/keywords/_element.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index b03002df5..9a4543229 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -54,8 +54,8 @@ 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, text, message=''): - """Verifies element identified by `locator` does not contain text `text`. + 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. @@ -63,12 +63,12 @@ def element_should_not_contain(self, locator, text, message=''): `Element Should Contain` for more details. """ self._info("Verifying element '%s' does not contain text '%s'." - % (locator, text)) + % (locator, expected)) actual = self._get_text(locator) - if text in actual: + if expected in actual: if not message: message = "Element '%s' should not contain text '%s' but " \ - "it did." % (locator, text) + "it did." % (locator, expected) raise AssertionError(message) def frame_should_contain(self, locator, text, loglevel='INFO'): From 59d95655c5db35b3d63a15652cde2279e6af5626 Mon Sep 17 00:00:00 2001 From: molsky Date: Mon, 11 May 2015 19:21:48 +0300 Subject: [PATCH 11/11] Update changelog --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) 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]