-
Notifications
You must be signed in to change notification settings - Fork 777
849 verify text case insensitive #1043
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
Changes from 10 commits
74fe713
0304060
d7467bf
5f7b978
6ec8e84
77de481
39cd590
ff293e8
31cbd12
8e84b22
e9f71d1
d135939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, message=None, ignore_case=False): | ||
"""Verifies that element ``locator`` contains text ``expected``. | ||
|
||
See the `Locating elements` section for details about the locator | ||
|
@@ -56,35 +56,54 @@ def element_should_contain(self, locator, expected, message=None): | |
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. | ||
""" | ||
actual = self.find_element(locator).text | ||
actual = actual_before = self.find_element(locator).text | ||
expected_before = expected | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not in favor of code blocks. Please remove the empty line from this line and from lines 71 and 76. |
||
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, 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): | ||
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 ``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 | ||
expected_before = expected | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not in favor of code blocks. Please remove the empty line from this line and from line 99. |
||
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 " \ | ||
"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'): | ||
|
@@ -288,7 +307,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, message=None, ignore_case=False): | ||
"""Verifies that element ``locator`` contains exact text ``expected``. | ||
|
||
See the `Locating elements` section for details about the locator | ||
|
@@ -297,16 +316,24 @@ def element_text_should_be(self, locator, expected, message=None): | |
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'." | ||
% (locator, expected)) | ||
text = self.find_element(locator).text | ||
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' " | ||
"but it was '%s'." | ||
% (locator, expected, text)) | ||
% (locator, expected, before_text)) | ||
raise AssertionError(message) | ||
|
||
@keyword | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,15 +119,20 @@ Page Should Not Contain Element With Disabling Source Logging | |
|
||
Element Should Contain | ||
Element Should Contain some_id This text is inside an identified element | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add line: |
||
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=False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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. | ||
|
@@ -138,10 +143,12 @@ 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 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 | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line here is not needed. |
||
Get Text | ||
${str} = Get Text some_id | ||
Should Match ${str} This text is inside an identified element | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In new line, add text:
ignore_case
argument is new in SeleniumLibrary 3.1.Please fix in keywords where the new argument is added.