How to convert string to uppercase / lowercase?

3,865 views
Skip to first unread message

Mário Godinho

unread,
Apr 4, 2012, 5:53:31 AM4/4/12
to robotframework-users
I need to convert a string into uppercase.
How can I do that with robot?
I searched in some robot libraries but none has a keyword for that...

Thanks in advance.

Janne Härkönen

unread,
Apr 4, 2012, 6:24:29 AM4/4/12
to robotframe...@googlegroups.com
Hello M�rio,

There are two options:

1) Use extended variable syntax [1] in an user keyword, like this:

***Keywords***
Uppercase [Arguments] ${string}
[Return] ${string.upper()}

2) Create your own library keyword [2]

def upper_case(string):
return string.upper()

[1]
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.7#extended-variable-syntax
[2]
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.7#creating-test-libraries

hope this helps,
--J


--
Janne H�rk�nen <|> Software Craftsman @ http://reaktor.fi
http://twitter.com/#!/janneharkonen

Mário Godinho

unread,
Apr 4, 2012, 6:32:55 AM4/4/12
to robotframe...@googlegroups.com
Thanks...

meanwhile I found out that I can do that also in my python robot input file :-):
MY_VAR=str.upper(my_small_var)


Quarta-feira, 4 de Abril de 2012 11h24min29s UTC+1, Janne Härkönen escreveu:
Hello M�rio,

On 04/04/2012 12:53 PM, M�rio Godinho wrote:
> I need to convert a string into uppercase.
> How can I do that with robot?
> I searched in some robot libraries but none has a keyword for that...

There are two options:

1) Use extended variable syntax [1] in an user keyword, like this:

***Keywords***
Uppercase   [Arguments]   ${string}
[Return]   ${string.upper()}

2) Create your own library keyword [2]

def upper_case(string):
     return string.upper()

[1]
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.7#extended-variable-syntax
[2]
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.7#creating-test-libraries

hope this helps,
--J


--
Janne H�rk�nen <|> Software Craftsman @ http://reaktor.fi
http://twitter.com/#!/janneharkonen

Pekka Klärck

unread,
Apr 5, 2012, 1:00:30 PM4/5/12
to joanab...@gmail.com, robotframe...@googlegroups.com
2012/4/4 Mário Godinho <joanab...@gmail.com>:

> Thanks...
>
> meanwhile I found out that I can do that also in my python robot input file
> :-):
> MY_VAR=str.upper(my_small_var)

This does work but using `MY_VAR = my_small_var.upper()` is more
common way to do it.

I actually thought String library would have keywords for
upper/lower/title casing strings. They surely could be added. Anyone
interested to implement them? At least an enhancement request could be
submitted to the tracker.

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