Running Keywords with arguments in keywords such as "Should Contain"

2,213 views
Skip to first unread message

kevin chong

unread,
Mar 7, 2012, 5:26:01 PM3/7/12
to robotframe...@googlegroups.com
Hello,

I'm trying to run the keyword "Should Be Empty" along with "Get IP Address" where I would like to pass in arguments to "Get IP Address". However, Since "Should Be Empty" also handles arguments, it takes "Get IP Address"'s argument and returns that string instead.

For example.

${retrieveIp}= Wait Until Keyword Succeeds 10 min 5 sec Should Not Contain None Get IP Address ${DUT_MAC}

I guess what i'm trying to achieve is this
while time != 10 minutes or keyword succeeds, run every 5 seconds{
Should Not Contain (None, (Get IP Address, ${DUT_MAC}))
}

Sorry, I'm not really good at describing things but I hope someone is able to help me out or point me in the right direction. Thanks!

Janne Härkönen

unread,
Mar 8, 2012, 1:28:43 AM3/8/12
to mr.kevi...@gmail.com, robotframe...@googlegroups.com
Hello Kevin,

On Thu, Mar 8, 2012 at 12:26 AM, kevin chong <mr.kevi...@gmail.com> wrote:
> I'm trying to run the keyword "Should Be Empty" along with "Get IP Address"
> where I would like to pass in arguments to "Get IP Address". However, Since
> "Should Be Empty" also handles arguments, it takes "Get IP Address"'s
> argument and returns that string instead.
>
> For example.
>
> ${retrieveIp}= Wait Until Keyword Succeeds 10 min 5 sec Should Not Contain
> None Get IP Address ${DUT_MAC}
>
> I guess what i'm trying to achieve is this
> while time != 10 minutes or keyword succeeds, run every 5 seconds{
> Should Not Contain (None, (Get IP Address, ${DUT_MAC}))
> }

Robot Framework does not allow chaining keyword calls like programming
languages allow chaining function calls. You must create a user
keyword that you use with Wait Until Keyword Succeeds, like this:

| ${retrieveIp}= | Wait Until Keyword Succeeds | 10 min | 5 sec | Get
Valid IP Address |

*** keywords ****

| Get Valid IP Address |
| ${ip}= | Get IP Address | ${DUT_MAC} |
| Should Not Contain | ${ip} | None |
| [Return] | ${ip} |

Haven't tested it, but barring typos it should work. If ${DUT_MAC} is
a local variable, you can of course make it an argument to `Get Valid
IP Address`.

hope this helps,
--J

kevin chong

unread,
Mar 8, 2012, 1:33:26 AM3/8/12
to robotframe...@googlegroups.com, mr.kevi...@gmail.com
hello Janne and thank you for your quick response. I didnt want to resolve to it but your suggestion is greatly appreciated! I will try that first thing tomorrow morning though I have no doubt it will work :) thanks again!

kevin chong

unread,
Mar 8, 2012, 11:57:44 AM3/8/12
to robotframe...@googlegroups.com, mr.kevi...@gmail.com
Ah Yes! Sorry! I remember why I did not do it this way. Sometimes I want to pass in values that is not ${DUT_MAC} and enter it in manually. By doing it your method, I believe it restricts me from doing so, without creating another keyword for that particular device and I do not find it really scalable. Would you happen to have another solution this by any chance? thanks!


On Thursday, March 8, 2012 1:28:43 AM UTC-5, Janne Härkönen wrote:

Janne Härkönen

unread,
Mar 8, 2012, 3:12:18 PM3/8/12
to mr.kevi...@gmail.com, robotframe...@googlegroups.com
Hello Kevin

On Thu, Mar 8, 2012 at 6:57 PM, kevin chong <mr.kevi...@gmail.com> wrote:
> Ah Yes! Sorry! I remember why I did not do it this way. Sometimes I want to
> pass in values that is not ${DUT_MAC} and enter it in manually. By doing it
> your method, I believe it restricts me from doing so, without creating
> another keyword for that particular device and I do not find it really
> scalable. Would you happen to have another solution this by any chance?
> thanks!

What do you mean by manually entering values? Could you provide a
concrete example that would help me understand this.

thanks,
--J

kevin chong

unread,
Mar 8, 2012, 3:18:45 PM3/8/12
to robotframe...@googlegroups.com, mr.kevi...@gmail.com
${deviceIP}= Get IP Address ${deviceMAC}
Should Not Contain ${deviceIP} None IP address could not be retrieved. False

sometimes I pass in ${deviceMAC} to get IP, however sometimes I manually type in 00:24:23:23:23:23:24 to get the IP for those odd cases I deal with more devices.

so if i pass in

${testIP}= Wait Until Keyword Succeeds 5 min 5 sec Get Valid IP

I can't explicitly write 

${testIP}= Wait Until Keyword Succeeds 5 min 5 sec Get Valid IP  00:24:23:23:23:23:24 

I was thinking of trying to add
${deviceMAC}= Set Variable ${DUTMAC} 
before i wait until keyword succeeds, but i dont want to have to initialize another variable if i dont have to. Sorry for the trouble!

Janne Härkönen

unread,
Mar 8, 2012, 3:41:48 PM3/8/12
to mr.kevi...@gmail.com, robotframe...@googlegroups.com
Hello Kevin,

On Thu, Mar 8, 2012 at 10:18 PM, kevin chong <mr.kevi...@gmail.com> wrote:
> ${deviceIP}= Get IP Address ${deviceMAC}
> Should Not Contain ${deviceIP} None IP address could not be retrieved. False
>
> sometimes I pass in ${deviceMAC} to get IP, however sometimes I manually
> type in 00:24:23:23:23:23:24 to get the IP for those odd cases I deal with
> more devices.
>
> so if i pass in
>
> ${testIP}= Wait Until Keyword Succeeds 5 min 5 sec Get Valid IP
>
> I can't explicitly write
>
> ${testIP}= Wait Until Keyword Succeeds 5 min 5 sec Get Valid
> IP  00:24:23:23:23:23:24
>
> I was thinking of trying to add
> ${deviceMAC}= Set Variable ${DUTMAC}
> before i wait until keyword succeeds, but i dont want to have to initialize
> another variable if i dont have to. Sorry for the trouble!

This can be easily accommodated with a user keyword taking arguments:

you use it either like

| {testIP}= | Wait Until Keyword Succeeds | 5 min | 5 sec | Get

Valid IP | ${deviceMAC} |

or

| {testIP}= | Wait Until Keyword Succeeds | 5 min | 5 sec | Get
Valid IP | 00:24:23:23:23:23:24 |

and the keyword implementation is

| Get Valid IP | [Arguments] | ${macAddr} |
| | ${deviceIP}= | Get IP Address | ${macAddr} |
| | Should Not Contain | ${deviceIP}= | None |
| | [Return] | ${deviceIP} | |


Now the ${macAddr} is local to the keyword, and can be defined in the call site.

hope this helps,
--J

kevin chong

unread,
Mar 8, 2012, 4:52:04 PM3/8/12
to robotframe...@googlegroups.com, mr.kevi...@gmail.com
oh how embarassing. I thought I tried that method but seems to be working :( thanks!
Reply all
Reply to author
Forward
0 new messages