From 74fe713893c1e0652d2f3e80579386cb78cc3cb4 Mon Sep 17 00:00:00 2001 From: rubygeek Date: Thu, 18 Jan 2018 17:27:36 -0600 Subject: [PATCH 01/11] added a feature where you can say ignore_case=True while the default is False --- src/SeleniumLibrary/keywords/element.py | 8 +++++++- .../acceptance/keywords/content_assertions.robot | 16 ++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index 6f999bb52..c6ec1b411 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -47,7 +47,7 @@ def get_webelements(self, locator): return self.find_elements(locator) @keyword - def element_should_contain(self, locator, expected, message=None): + def element_should_contain(self, locator, expected, ignore_case=False, message=None): """Verifies that element ``locator`` contains text ``expected``. See the `Locating elements` section for details about the locator @@ -60,10 +60,16 @@ def element_should_contain(self, locator, expected, message=None): not a substring. """ actual = self.find_element(locator).text + + if ignore_case: + actual = actual.lower() + expected = expected.lower() + if expected not in actual: if is_noney(message): message = "Element '%s' should have contained text '%s' but "\ "its text was '%s'." % (locator, expected, actual) + raise AssertionError(message) self.info("Element '%s' contains text '%s'." % (locator, expected)) diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index 7624de11f..6e1cc6c49 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -114,13 +114,17 @@ Page Should Not Contain Element With Disabling Source Logging [Teardown] Set Log Level DEBUG Element Should Contain + [Tags] focusnola Element Should Contain some_id This text is inside an identified element - 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 - ... Element with locator 'missing_id' not found. - ... Element Should Contain missing_id This should report missing element. + Element Should Contain some_id THIS TEXT IS INSIDE AN IDENTIFIED ELEMENT ignore_case=True + Element Should Contain some_id This text is inside an identified elemenT ignore_case=False message=This Passed blah blah + + # 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 + # ... Element with locator 'missing_id' not found. + # ... 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 From 030406030a9e8d61d1f0d3a14ec7f9a12901330f Mon Sep 17 00:00:00 2001 From: rubygeek Date: Fri, 19 Jan 2018 13:28:22 -0600 Subject: [PATCH 02/11] fixed typo, added doc string info on new params --- src/SeleniumLibrary/keywords/element.py | 5 ++++- test/acceptance/keywords/content_assertions.robot | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index c6ec1b411..d01527ba8 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -53,6 +53,9 @@ def element_should_contain(self, locator, expected, ignore_case=False, message=N See the `Locating elements` section for details about the locator syntax. + The ``ignore_case`` argumentcan be set to True to compare case + insensitive, default is False. + The ``message`` argument can be used to override the default error message. @@ -69,7 +72,7 @@ def element_should_contain(self, locator, expected, ignore_case=False, message=N if is_noney(message): message = "Element '%s' should have contained text '%s' but "\ "its text was '%s'." % (locator, expected, actual) - + raise AssertionError(message) self.info("Element '%s' contains text '%s'." % (locator, expected)) diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index 6e1cc6c49..10ad26339 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -117,7 +117,7 @@ Element Should Contain [Tags] focusnola Element Should Contain some_id This text is inside an identified element Element Should Contain some_id THIS TEXT IS INSIDE AN IDENTIFIED ELEMENT ignore_case=True - Element Should Contain some_id This text is inside an identified elemenT ignore_case=False message=This Passed blah blah + Element Should Contain some_id This text is inside an identified elemenT ignore_case=False # 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'. From d7467bf9b768ddf9cb3d53f4479a39b3ba9fbe2a Mon Sep 17 00:00:00 2001 From: rubygeek Date: Fri, 19 Jan 2018 13:32:20 -0600 Subject: [PATCH 03/11] removed testing tag --- test/acceptance/keywords/content_assertions.robot | 1 - 1 file changed, 1 deletion(-) diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index 10ad26339..ba66414db 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -114,7 +114,6 @@ Page Should Not Contain Element With Disabling Source Logging [Teardown] Set Log Level DEBUG Element Should Contain - [Tags] focusnola Element Should Contain some_id This text is inside an identified element Element Should Contain some_id THIS TEXT IS INSIDE AN IDENTIFIED ELEMENT ignore_case=True Element Should Contain some_id This text is inside an identified elemenT ignore_case=False From 5f7b978f7c38c36f8c416b1de323edb7995b470f Mon Sep 17 00:00:00 2001 From: rubygeek Date: Fri, 19 Jan 2018 14:29:54 -0600 Subject: [PATCH 04/11] WIP --- src/SeleniumLibrary/keywords/element.py | 21 +++++++++++++++---- .../keywords/content_assertions.robot | 18 +++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index d01527ba8..e72b10b5c 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -53,7 +53,7 @@ def element_should_contain(self, locator, expected, ignore_case=False, message=N See the `Locating elements` section for details about the locator syntax. - The ``ignore_case`` argumentcan be set to True to compare case + The ``ignore_case`` argument can be set to True to compare case insensitive, default is False. The ``message`` argument can be used to override the default error @@ -64,7 +64,7 @@ def element_should_contain(self, locator, expected, ignore_case=False, message=N """ actual = self.find_element(locator).text - if ignore_case: + if is_truthy(ignore_case): actual = actual.lower() expected = expected.lower() @@ -77,16 +77,24 @@ def element_should_contain(self, locator, expected, ignore_case=False, message=N self.info("Element '%s' contains text '%s'." % (locator, expected)) @keyword - def element_should_not_contain(self, locator, expected, message=None): + def element_should_not_contain(self, locator, expected, ignore_case=False, message=None): """Verifies that element ``locator`` does not contains text ``expected``. See the `Locating elements` section for details about the locator syntax. + The ``ignore_case`` argument can be set to True to compare case + insensitive, default is False. + The ``message`` argument can be used to override the default error message. """ actual = self.find_element(locator).text + + if is_truthy(ignore_case): + actual = actual.lower() + expected = expected.lower() + if expected in actual: if is_noney(message): message = "Element '%s' should not contain text '%s' but " \ @@ -297,7 +305,7 @@ def element_should_not_be_visible(self, locator, message=None): raise AssertionError(message) @keyword - def element_text_should_be(self, locator, expected, message=None): + def element_text_should_be(self, locator, expected, ignore_case=False, message=None): """Verifies that element ``locator`` contains exact text ``expected``. See the `Locating elements` section for details about the locator @@ -311,6 +319,11 @@ def element_text_should_be(self, locator, expected, message=None): self.info("Verifying element '%s' contains exact text '%s'." % (locator, expected)) text = self.find_element(locator).text + + if is_truthy(ignore_case): + text = text.lower() + expected = expected.lower() + if text != expected: if is_noney(message): message = ("The text of element '%s' should have been '%s' " diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index ba66414db..86abb5584 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -116,17 +116,19 @@ Page Should Not Contain Element With Disabling Source Logging Element Should Contain Element Should Contain some_id This text is inside an identified element Element Should Contain some_id THIS TEXT IS INSIDE AN IDENTIFIED ELEMENT ignore_case=True - Element Should Contain some_id This text is inside an identified elemenT ignore_case=False - # 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 - # ... Element with locator 'missing_id' not found. - # ... Element Should Contain missing_id This should report missing element. + 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 + ... Element Shoudl Conyain some_id THIS TEXT + Run Keyword And Expect Error + ... Element with locator 'missing_id' not found. + ... Element Should Contain missing_id This should report missing element. Element Should Not Contain + [Tags] focus Element Should Not Contain some_id This text is not inside an identified element + Element Should Not Contain some_id text ignore_case=True 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. @@ -136,7 +138,9 @@ Element Should Not Contain ... 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 + Element Text Should Be some_id This text is inside an identified element ignore_case=True Run Keyword And Expect Error ... The text of element 'some_id' should have been 'inside' but it was 'This text is inside an identified element'. ... Element Text Should Be some_id inside From 6ec8e840ccde92e36ea119654aeff1664652bfaa Mon Sep 17 00:00:00 2001 From: rubygeek Date: Mon, 22 Jan 2018 15:50:15 -0600 Subject: [PATCH 05/11] updated --- test/acceptance/keywords/content_assertions.robot | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index 86abb5584..4eb706b25 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -120,13 +120,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 - ... Element Shoudl Conyain some_id THIS TEXT Run Keyword And Expect Error ... Element with locator 'missing_id' not found. ... Element Should Contain missing_id This should report missing element. Element Should Not Contain - [Tags] focus Element Should Not Contain some_id This text is not inside an identified element Element Should Not Contain some_id text ignore_case=True Element Should Not Contain some_id elementypo @@ -138,13 +136,14 @@ Element Should Not Contain ... Element Should Not Contain missing_id This should report missing element. Element Text Should Be - + [Tags] focus Element Text Should Be some_id This text is inside an identified element - Element Text Should Be some_id This text is inside an identified element ignore_case=True + Element Text Should Be some_id This TEST IS INSIDE ignore_case=True Run Keyword And Expect Error ... The text of element 'some_id' should have been 'inside' but it was 'This text is inside an identified element'. ... Element Text Should Be some_id inside + Get Text ${str} = Get Text some_id Should Match ${str} This text is inside an identified element From 77de48131f3c766d0803f02a35e032bcd3c7f860 Mon Sep 17 00:00:00 2001 From: rubygeek Date: Mon, 22 Jan 2018 16:12:57 -0600 Subject: [PATCH 06/11] updated --- src/SeleniumLibrary/keywords/element.py | 3 +++ test/acceptance/keywords/content_assertions.robot | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index e72b10b5c..95b946e6b 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -311,6 +311,9 @@ def element_text_should_be(self, locator, expected, ignore_case=False, message=N See the `Locating elements` section for details about the locator syntax. + The ``ignore_case`` argument can be set to True to compare case + insensitive, default is False. + The ``message`` argument can be used to override the default error message. diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index 4eb706b25..a171d10da 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -126,7 +126,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 text ignore_case=True + Element Should Not Contain some_id THIS TEXT is not inside an identified element ignore_case=True 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. @@ -136,7 +136,6 @@ Element Should Not Contain ... Element Should Not Contain missing_id This should report missing element. Element Text Should Be - [Tags] focus Element Text Should Be some_id This text is inside an identified element Element Text Should Be some_id This TEST IS INSIDE ignore_case=True Run Keyword And Expect Error From 39cd5906af4c339c73ffa22483e48df3a055e958 Mon Sep 17 00:00:00 2001 From: rubygeek Date: Tue, 23 Jan 2018 12:52:07 -0600 Subject: [PATCH 07/11] moved position in doc string --- src/SeleniumLibrary/keywords/element.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index 95b946e6b..7adf953e5 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -47,18 +47,18 @@ def get_webelements(self, locator): return self.find_elements(locator) @keyword - def element_should_contain(self, locator, expected, ignore_case=False, message=None): + def element_should_contain(self, locator, expected, message=None, ignore_case=False): """Verifies that element ``locator`` contains text ``expected``. See the `Locating elements` section for details about the locator syntax. - The ``ignore_case`` argument can be set to True to compare case - insensitive, default is False. - The ``message`` argument can be used to override the default error message. + The ``ignore_case`` argument can be set to True to compare case + insensitive, default is False. + Use `Element Text Should Be` if you want to match the exact text, not a substring. """ @@ -77,17 +77,17 @@ def element_should_contain(self, locator, expected, ignore_case=False, message=N self.info("Element '%s' contains text '%s'." % (locator, expected)) @keyword - def element_should_not_contain(self, locator, expected, ignore_case=False, message=None): + def element_should_not_contain(self, locator, expected, message=None, ignore_case=False ): """Verifies that element ``locator`` does not contains text ``expected``. See the `Locating elements` section for details about the locator syntax. - The ``ignore_case`` argument can be set to True to compare case - insensitive, default is False. - The ``message`` argument can be used to override the default error message. + + The ``ignore_case`` argument can be set to True to compare case + insensitive, default is False. """ actual = self.find_element(locator).text @@ -305,18 +305,18 @@ def element_should_not_be_visible(self, locator, message=None): raise AssertionError(message) @keyword - def element_text_should_be(self, locator, expected, ignore_case=False, message=None): + def element_text_should_be(self, locator, expected, message=None, ignore_case=False): """Verifies that element ``locator`` contains exact text ``expected``. See the `Locating elements` section for details about the locator syntax. - The ``ignore_case`` argument can be set to True to compare case - insensitive, default is False. - The ``message`` argument can be used to override the default error message. + The ``ignore_case`` argument can be set to True to compare case + insensitive, default is False. + Use `Element Should Contain` if a substring match is desired. """ self.info("Verifying element '%s' contains exact text '%s'." From ff293e88188050f76da62f3ce663ad4c608a3227 Mon Sep 17 00:00:00 2001 From: rubygeek Date: Fri, 2 Feb 2018 20:00:12 -0600 Subject: [PATCH 08/11] added a test case for ignore_case=True when the text is not going to match to test it is false case --- src/SeleniumLibrary/keywords/element.py | 16 +++++++++------- .../acceptance/keywords/content_assertions.robot | 8 +++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index 7adf953e5..cd14786fb 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -62,7 +62,8 @@ def element_should_contain(self, locator, expected, message=None, ignore_case=Fa Use `Element Text Should Be` if you want to match the exact text, not a substring. """ - actual = self.find_element(locator).text + actual = actual_before = self.find_element(locator).text + expected_before = expected if is_truthy(ignore_case): actual = actual.lower() @@ -71,10 +72,10 @@ def element_should_contain(self, locator, expected, message=None, ignore_case=Fa if expected not in actual: if is_noney(message): message = "Element '%s' should have contained text '%s' but "\ - "its text was '%s'." % (locator, expected, actual) + "its text was '%s'." % (locator, expected_before, actual_before) raise AssertionError(message) - self.info("Element '%s' contains text '%s'." % (locator, expected)) + self.info("Element '%s' contains text '%s'." % (locator, expected_before)) @keyword def element_should_not_contain(self, locator, expected, message=None, ignore_case=False ): @@ -90,6 +91,7 @@ def element_should_not_contain(self, locator, expected, message=None, ignore_cas insensitive, default is False. """ actual = self.find_element(locator).text + expected_before = expected if is_truthy(ignore_case): actual = actual.lower() @@ -98,10 +100,10 @@ def element_should_not_contain(self, locator, expected, message=None, ignore_cas if expected in actual: if is_noney(message): message = "Element '%s' should not contain text '%s' but " \ - "it did." % (locator, expected) + "it did." % (locator, expected_before) raise AssertionError(message) self.info("Element '%s' does not contain text '%s'." - % (locator, expected)) + % (locator, expected_before)) @keyword def page_should_contain(self, text, loglevel='INFO'): @@ -321,7 +323,7 @@ def element_text_should_be(self, locator, expected, message=None, ignore_case=Fa """ self.info("Verifying element '%s' contains exact text '%s'." % (locator, expected)) - text = self.find_element(locator).text + text = before_text = self.find_element(locator).text if is_truthy(ignore_case): text = text.lower() @@ -331,7 +333,7 @@ def element_text_should_be(self, locator, expected, message=None, ignore_case=Fa if is_noney(message): message = ("The text of element '%s' should have been '%s' " "but it was '%s'." - % (locator, expected, text)) + % (locator, expected, before_text)) raise AssertionError(message) @keyword diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index a171d10da..6a00f587b 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -116,17 +116,19 @@ Page Should Not Contain Element With Disabling Source Logging Element Should Contain Element Should Contain some_id This text is inside an identified element Element Should Contain some_id THIS TEXT IS INSIDE AN IDENTIFIED ELEMENT ignore_case=True - 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 ... Element with locator 'missing_id' not found. ... Element Should Contain missing_id This should report missing element. + Run Keyword And Expect Error + ... Element 'some_id' should have contained text 'foobar' but its text was 'This text is inside an identified element'. + ... Element Should Contain some_id foobar ignore_case=True Element Should Not Contain Element Should Not 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 ignore_case=True + Element Should Not Contain some_id THIS TEXT is not inside an identified element ignore_case=False 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. @@ -137,7 +139,7 @@ Element Should Not Contain Element Text Should Be Element Text Should Be some_id This text is inside an identified element - Element Text Should Be some_id This TEST IS INSIDE ignore_case=True + Element Text Should Be some_id This TEXT IS INSIDE AN IDENTIFIED ELEMENT ignore_case=True Run Keyword And Expect Error ... The text of element 'some_id' should have been 'inside' but it was 'This text is inside an identified element'. ... Element Text Should Be some_id inside From 8e84b22d89287f6cb2ad1ad2762f3926a8512741 Mon Sep 17 00:00:00 2001 From: rubygeek Date: Sat, 3 Feb 2018 14:08:47 -0600 Subject: [PATCH 09/11] added what is new in changes file --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 2d64c6c5f..93a52a833 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Release Notes 3.1.0 ----- - Added a message param to `Title Should Be` to display custom error message [rubygeek] +- Compare text regardless of case in: `Element Should Contain`, `Element Should Not Contain` and `Element Text Should Be` by passing `ignore_case=True`. The default is `False` 3.0.0 ----- From e9f71d137fbba9d5a83cdaea0a0162570c785bc3 Mon Sep 17 00:00:00 2001 From: rubygeek Date: Sun, 11 Feb 2018 16:45:52 -0600 Subject: [PATCH 10/11] updated tests --- src/SeleniumLibrary/keywords/element.py | 14 ++++++++------ test/acceptance/keywords/content_assertions.robot | 12 ++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index cd14786fb..31c80e796 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -57,7 +57,9 @@ def element_should_contain(self, locator, expected, message=None, ignore_case=Fa message. The ``ignore_case`` argument can be set to True to compare case - insensitive, default is False. + insensitive, default is False. New in SeleniumLibrary 3.1. + + ``ignore_case`` argument new in SeleniumLibrary 3.1. Use `Element Text Should Be` if you want to match the exact text, not a substring. @@ -68,12 +70,10 @@ def element_should_contain(self, locator, expected, message=None, ignore_case=Fa if is_truthy(ignore_case): actual = actual.lower() expected = expected.lower() - if expected not in actual: if is_noney(message): message = "Element '%s' should have contained text '%s' but "\ "its text was '%s'." % (locator, expected_before, actual_before) - raise AssertionError(message) self.info("Element '%s' contains text '%s'." % (locator, expected_before)) @@ -89,14 +89,14 @@ def element_should_not_contain(self, locator, expected, message=None, ignore_cas The ``ignore_case`` argument can be set to True to compare case insensitive, default is False. + + ``ignore_case`` argument new in SeleniumLibrary 3.1. """ actual = self.find_element(locator).text expected_before = expected - if is_truthy(ignore_case): actual = actual.lower() - expected = expected.lower() - + expected = expected.lower() if expected in actual: if is_noney(message): message = "Element '%s' should not contain text '%s' but " \ @@ -319,6 +319,8 @@ def element_text_should_be(self, locator, expected, message=None, ignore_case=Fa The ``ignore_case`` argument can be set to True to compare case insensitive, default is False. + ``ignore_case`` argument new in SeleniumLibrary 3.1. + Use `Element Should Contain` if a substring match is desired. """ self.info("Verifying element '%s' contains exact text '%s'." diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index 62041f01a..0a16fd7d7 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -120,6 +120,7 @@ Page Should Not Contain Element With Disabling Source Logging Element Should Contain Element Should Contain some_id This text is inside an identified element Element Should Contain some_id THIS TEXT IS INSIDE AN IDENTIFIED ELEMENT ignore_case=True + Element Should Contain some_id This text is inside an identified element ignore_case=False 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 @@ -127,17 +128,21 @@ Element Should Contain ... Element with locator 'missing_id' not found. ... Element Should Contain missing_id This should report missing element. Run Keyword And Expect Error - ... Element 'some_id' should have contained text 'foobar' but its text was 'This text is inside an identified element'. - ... Element Should Contain some_id foobar ignore_case=True + ... Element 'some_id' should have contained text 'THIS TEXT' but its text was 'This text is inside an identified element'. + ... Element Should Contain some_id THIS TEXT ignore_case=False Element Should Not Contain Element Should Not 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 ignore_case=False + Element Should Not Contain some_id This text is not inside an identified element ignore_case=False + Element Should Not Contain some_id THIS TEXT is not inside an identified element ignore_case=True 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 + ... Element 'some_id' should not contain text 'TEXT' but it did. + ... Element Should Not Contain some_id TEXT ignore_case=True + Run Keyword And Expect Error ... Element with locator 'missing_id' not found. ... Element Should Not Contain missing_id This should report missing element. @@ -148,7 +153,6 @@ Element Text Should Be ... The text of element 'some_id' should have been 'inside' but it was 'This text is inside an identified element'. ... Element Text Should Be some_id inside - Get Text ${str} = Get Text some_id Should Match ${str} This text is inside an identified element From d13593922a2425619f635ecedd78323d304be3bf Mon Sep 17 00:00:00 2001 From: rubygeek Date: Sun, 11 Feb 2018 18:24:59 -0600 Subject: [PATCH 11/11] fixing few more things from the review --- src/SeleniumLibrary/keywords/element.py | 5 +---- test/acceptance/keywords/content_assertions.robot | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index 31c80e796..ce8226a0b 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -66,7 +66,6 @@ def element_should_contain(self, locator, expected, message=None, ignore_case=Fa """ actual = actual_before = self.find_element(locator).text expected_before = expected - if is_truthy(ignore_case): actual = actual.lower() expected = expected.lower() @@ -96,7 +95,7 @@ def element_should_not_contain(self, locator, expected, message=None, ignore_cas expected_before = expected if is_truthy(ignore_case): actual = actual.lower() - expected = expected.lower() + expected = expected.lower() if expected in actual: if is_noney(message): message = "Element '%s' should not contain text '%s' but " \ @@ -326,11 +325,9 @@ def element_text_should_be(self, locator, expected, message=None, ignore_case=Fa self.info("Verifying element '%s' contains exact text '%s'." % (locator, expected)) text = before_text = self.find_element(locator).text - if is_truthy(ignore_case): text = text.lower() expected = expected.lower() - if text != expected: if is_noney(message): message = ("The text of element '%s' should have been '%s' " diff --git a/test/acceptance/keywords/content_assertions.robot b/test/acceptance/keywords/content_assertions.robot index 0a16fd7d7..38d295199 100644 --- a/test/acceptance/keywords/content_assertions.robot +++ b/test/acceptance/keywords/content_assertions.robot @@ -130,6 +130,9 @@ Element Should Contain Run Keyword And Expect Error ... Element 'some_id' should have contained text 'THIS TEXT' but its text was 'This text is inside an identified element'. ... Element Should Contain some_id THIS TEXT ignore_case=False + Run Keyword And Expect Error + ... Element 'some_id' should have contained text 'foobar' but its text was 'This text is inside an identified element'. + ... Element Should Contain some_id foobar ignore_case=True Element Should Not Contain Element Should Not Contain some_id This text is not inside an identified element @@ -143,6 +146,9 @@ Element Should Not Contain ... Element 'some_id' should not contain text 'TEXT' but it did. ... Element Should Not Contain some_id TEXT ignore_case=True Run Keyword And Expect Error + ... Element 'some_id' should not contain text 'text' but it did. + ... Element Should Not Contain some_id text ignore_case=False + Run Keyword And Expect Error ... Element with locator 'missing_id' not found. ... Element Should Not Contain missing_id This should report missing element.