Keyword to Sort List Ignore Case

774 views
Skip to first unread message

Raghavendra pokuri

unread,
May 21, 2014, 10:41:01 PM5/21/14
to robotframe...@googlegroups.com
we have Sort List Keyword. But in my case i have to use Sort List Ignore case, how to implement this do we have any keyword for this. Please help me. Quick reply would be very helpful.


Thanks

Laurent Bristiel

unread,
May 22, 2014, 4:02:32 AM5/22/14
to robotframe...@googlegroups.com
Hello,

this is not available natively in Robot Framework.
You will have to implement it in your own library.

I found a possible implementation in Stack Overflow:
http://stackoverflow.com/questions/10269701/case-insensitive-list-sorting-without-lowercasing-the-result

Here is how it would work in Robot:
1) create a lib.py file:
def custom_sort(list):
    return sorted(list, key=lambda s: s.lower())

2) use this lib in your test:
*** Settings ***
library  lib
library  Collections

*** test cases ***
test
    ${list} =  create list  Aden  benjamin  abel
    ${custom_sorted_list} =  custom_sort  ${list}
    sort list  ${list}
    log to console  \n${list}
    log to console  \n${custom_sorted_list}
   
3) if you run this test, you will get:
MBP]$ pybot ts.txt
==============================================================================
Ts
==============================================================================
test                                                                  ...
[u'Aden', u'abel', u'benjamin']
[u'abel', u'Aden', u'benjamin']
test                                                                  | PASS |

Which is what you are looking for I think.

Hope this helps,
Laurent Bristiel
Reply all
Reply to author
Forward
0 new messages