Set Variables If Something is None/Null

8,172 views
Skip to first unread message

green

unread,
Jan 5, 2009, 4:55:52 AM1/5/09
to robotframe...@googlegroups.com
Hi, 

How to set a variable conditionally if another variable is None/null? 

I tried to use "Set Variable If<tab>${MY_VAR}==${null}", it will failed with lexical error during evaluation.

Regards,
Green

Pekka Klärck

unread,
Jan 5, 2009, 6:34:45 AM1/5/09
to green...@gmail.com, robotframe...@googlegroups.com
2009/1/5 green <green...@gmail.com>:

> How to set a variable conditionally if another variable is None/null?
> I tried to use "Set Variable If<tab>${MY_VAR}==${null}", it will failed with
> lexical error during evaluation.

I assume that what you tried actually works if ${MY_VAR} is null, but
if it's e.g. a string evaluating the expression fails. You could try
using quotes around both ${MY_VAR} and ${null} but then the expression
is true also if ${MY_VAR} contains string "None" (Jython converts null
to None automatically). One possibility would be using following
construct, but it gets a bit complicated.

| ${status} | ${ignored}= | Run Keyword And Expect Error | Should Be
Equal | ${MY_VAR} | ${null}
| Set Variable If | "${status}" == "PASS" | xxx | yyy |

It might be best that you create a special keyword for this in your
library. Alternatively keyword(s) that get the value of ${MY_VAR} can
check is the value null or not.

Cheers,
.peke

green

unread,
Jan 5, 2009, 8:02:43 AM1/5/09
to Pekka Klärck, robotframe...@googlegroups.com
Many thanks, Pekka. What if add a keyword "Set Variable If None" to the Build-In library? b/c I think this might quite frequently used.

Pekka Klärck

unread,
Jan 5, 2009, 9:32:00 AM1/5/09
to green, robotframe...@googlegroups.com
2009/1/5 green <green...@gmail.com>:

> Many thanks, Pekka. What if add a keyword "Set Variable If None" to the
> Build-In library? b/c I think this might quite frequently used.

I'm not sure would Set Variable If None be that commonly used. Please
submit an enhancement request to the tracker anyway. If it gets enough
votes (i.e. stars) we can add it in the future.

Cheers,
.peke

Reply all
Reply to author
Forward
0 new messages