I just wnat to ask you if you know an easy way to verify a website Text with a case insensitive focus.
I mean, for example check that Praga text it’s into a particular website using a keyword like:
Page Should Contain Praga
But keeping in mind that for us it’s is valid algo values like “praga”, “pRaga”, pragA", etc…
I know that i can build an .py file to difine a function like:
def compare_strings_case_insensitive(string1, string2):
return string1.lower() == string2.lower()
or write RF code like:
${text} Get Text # Replace this with the actual keyword to get the text from the page
Run Keyword If ‘Praga’ in ${text} OR ‘praga’ in ${text}
… ELSE Fail The page does not contain ‘Praga’ or ‘praga’
But i’m looking for a easier way like a param or action inside some RF buildIn keywords.
Well String library has Convert To Lower Case so you cold use that, but likewise you can use python variable methods on robot framework variables as well, so you can do this which is probably easier:
*** Test Cases ***
Case Insensitive Example
${var1}= Set Variable pRaga
${var2}= Set Variable pragA
Should Be Equal As Strings ${var1.lower()} ${var2.lower()}
Hi @damies13
Thanks for your support, this looks fine for me as it’s an easier approach to solve my problem but i was looking for something different and maybe i didn’t explain good enough my question.
Imagine that i have to check that, a particular web site have the string "user@company.com" just that simple validation.
Arguments to a keyword are up to the implementation of the library that the keyword comes from, there is no set of standard arguments that apply to all libraries, some keywords can even have no arguments (again it’s up to the implementation)
I’m guessing the Page Should Contain is this one from SeleniumLibrary? if so It only has 2 arguments shown in it’s documentation, so it appears no there’s no easy way to tell it to ignore case.
I guess something like this might do what you want:
Page Should Contain Element //*[contains(translate(text(),'ABCDEFGHIJKLMNOPURSTUWXYZ','abcdefghijklmnopurstuwxyz'), 'user@company.com')]
I initially tried to use the xpath //*[contains(lower-case(text()), 'user@company.com')] but it didn’t work (even outside robot framework), I don’t really know why but a quick google put me onto the translate() trick and that xpath worked in the browser dev tools for this page, so hopefully this will work for you.
If you need to use it often you might want to wrap it in a keyword like this:
*** Test Cases ***
Case Insensitive Example 2
Page Should Contain Case Insensitive User@Company.com
*** Keywords ***
Page Should Contain Case Insensitive
[Arguments] ${searchtext}
Page Should Contain Element //*[contains(translate(text(),'ABCDEFGHIJKLMNOPURSTUWXYZ','abcdefghijklmnopurstuwxyz'), '${searchtext.lower()}')]
lower-case is in xpath 2.0 which browsers generally don’t support. For all practical intents and purposes, it seems xpath 1.0 is the last version there will ever be. I tried to make some sense of the reasons; it seems like no one wants to include anything new xml related.