String's "equalsIgnoreCase" function in Robot framework

2,801 views
Skip to first unread message

sharmar...@gmail.com

unread,
Aug 31, 2016, 12:46:24 AM8/31/16
to robotframework-users
Hi All,
         I have a scenario where i have to compare two string regardless of its Case(lowercase/uppercase). i tried using Should Be Equal keyword from BuiltIn library but that seems to be not working. Do we have any keyword or argument to any keyword that works similar to equalsIgnoreCase function from String. i have looked around Built in and String Libraries but didn't get anything yet.


any help would be much appriciated.

~Ravindra

dm08

unread,
Aug 31, 2016, 1:14:34 AM8/31/16
to sharmar...@gmail.com, robotframework-users
Hi,

First of all you can use Convert To Lowercase(Uppercase) keyword to
 convert sting and then compare them.
Secondly you may use Should Be True  keyword with condition
f.e     Should Be True   ${str1.upper()} == ${str2.upper()}

Thanks,
Dmitriy

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

sharmar...@gmail.com

unread,
Aug 31, 2016, 1:50:22 AM8/31/16
to robotframework-users, sharmar...@gmail.com
Hi Dmitriy,
                 Thanks for quick reply, i am sure this will work with a string but i have more complicated situation here. I am trying to compare two list<String> with should be Equal keyword and here i have to consider case insensitive part.

i tried applying Convert To Lowercase keyword on list but it throws error:  AttributeError: 'java.util.ArrayList' object has no attribute 'lower'

Regards,
~Ravindra

On Wednesday, August 31, 2016 at 10:44:34 AM UTC+5:30, stn1k3 wrote:
Hi,

First of all you can use Convert To Lowercase(Uppercase) keyword to
 convert sting and then compare them.
Secondly you may use Should Be True  keyword with condition
f.e     Should Be True   ${str1.upper()} == ${str2.upper()}

Thanks,
Dmitriy
On Aug 30, 2016, at 9:40 PM, sharmar...@gmail.com wrote:

Hi All,
         I have a scenario where i have to compare two string regardless of its Case(lowercase/uppercase). i tried using Should Be Equal keyword from BuiltIn library but that seems to be not working. Do we have any keyword or argument to any keyword that works similar to equalsIgnoreCase function from String. i have looked around Built in and String Libraries but didn't get anything yet.


any help would be much appriciated.

~Ravindra

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Tatu Aalto

unread,
Aug 31, 2016, 1:59:09 AM8/31/16
to sharmar...@gmail.com, robotframework-users

Ugh

If you convert the strings first to lower case[1] and then compare the strings you should get the result what you are looking for.

-Tatu
Send from my mobile
[1] http://robotframework.org/robotframework/latest/libraries/String.html#Convert%20To%20Lowercase


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.

dm08

unread,
Aug 31, 2016, 2:02:14 AM8/31/16
to sharmar...@gmail.com, robotframework-users
Because it is a sequence you have to iterate though it and convert all items one by one.
Look into for look and collections library.

Thanks,
Dmitriy
 
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.

dm08

unread,
Aug 31, 2016, 2:20:53 AM8/31/16
to sharmar...@gmail.com, robotframework-users
I think there is another more elegant solution is to create string from sequence and them do convert case only once 
f.e.
${actual_list}=     Keyword That Returns Array List
${catenated_string}=     Catenate     @{actual_list}
${expected_result}=     item1    item2  
${actual_result}=    Convert To Lowercase    ${catenated_string}
Should Be Equal    ${expected_result}    ${actual_result}
or 
Should Be True      ${expected_result} == ${catenated_string.lower()}

Thanks,
Dmitriy
Message has been deleted

Pekka Klärck

unread,
Aug 31, 2016, 2:35:10 PM8/31/16
to sharmar...@gmail.com, robotframework-users
2016-08-31 7:40 GMT+03:00 <sharmar...@gmail.com>:
> Hi All,
> I have a scenario where i have to compare two string regardless of
> its Case(lowercase/uppercase). i tried using Should Be Equal keyword from
> BuiltIn library but that seems to be not working. Do we have any keyword or
> argument to any keyword that works similar to equalsIgnoreCase function from
> String. i have looked around Built in and String Libraries but didn't get
> anything yet.

As others pointed out, there's no built-in keyword to do this, but you
can convert strings to lowercase first and use various comparison
keywords after that. That said, it might be a good idea to add an
optional argument to comparison keywords to turn validation
case-insensitive. Perhaps it could work like this:

Should Be Equal ${string} expected ignore_case=True
Should Contain ${list} expected ignore_case=True

There are *many* such keywords in BuiltIn and String libraries and
adding this argument to all of them is somewhat big task, but I guess
it would be worth it in the long run. What do others think? Anyone
likes this enough to consider providing a pull request?

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
Reply all
Reply to author
Forward
0 new messages