Run Keyword if... I got a problem

210 views
Skip to first unread message

elab...@handpoint.com

unread,
Oct 4, 2017, 5:53:34 AM10/4/17
to robotframework-users
Hello,

I'm pretty stuck with this problem..

I run RF on IronPython, this is a part of a keyword:

   
run keyword if ${someVar} == 'AUTHORISED' log ${someVar} INFO
... ELSE log ${someVar} ERROR

And I get this error:
Evaluating expression 'AUTHORISED == AUTHORISED' failed: NameError: name 'AUTHORISED' is not defined

I have seen in the list and in the guide different ways to write this so I tried the following:

    run keyword if    '${someVar}' == 'AUTHORISED'    log  ${someVar}  INFO
... ELSE log ${someVar} ERROR

getting almost the same output:

Evaluating expression 'AUTHORISED == AUTHORISED'' failed: NameError: name 'AUTHORISED' is not defined


I tried setting another variable containing AUTHORISED 

    run keyword if    ${someVar} == ${anotherVar} log  ${someVar}  INFO
...  ELSE    log ${someVar}  ERROR

But I get the same message again.
I played with the " ' " and with the " == " and I also removed the braces as I read in the guide this was possible.


    run keyword if    $someVar == $anotherVar log  $someVar  INFO
...  ELSE    log $someVar  ERROR

But then it is not reading the variable, it is simply logging $someVar.

Can someone please point what I am doing wrong?

Thanks,

Elena


Alex C.

unread,
Oct 4, 2017, 6:44:30 AM10/4/17
to robotframe...@googlegroups.com
The problem is the number of spaces in the evaluating syntax:

run keyword if     '${someVar}'=='AUTHORISED'

or

run keyword if     $someVar == 'AUTHORISED'

Should both work fine.

Some addition from evaluating expressions: "Most importantly, strings must always be quoted, and if they can contain newlines, they must be triple quoted."  - http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Evaluating%20expressions

elab...@handpoint.com

unread,
Oct 4, 2017, 7:02:56 AM10/4/17
to robotframework-users
It works, thanks.
I got the feeling it was something stupid, and so was it. In the rest of keywords I got spaces between = so that didn't ring the bell. 



On Wednesday, October 4, 2017 at 12:44:30 PM UTC+2, Alex C. wrote:
The problem are the spaces in the evaluating syntax:

run keyword if     '${someVar}'=='AUTHORISED'

Alex C.

unread,
Oct 4, 2017, 7:54:30 AM10/4/17
to robotframework-users
It works with spaces as well when you use this syntax:

run keyword if     $someVar == 'AUTHORISED'

Here you have to be careful not to have two spaces between each argument, but one is ok.

Pekka Klärck

unread,
Oct 4, 2017, 11:31:31 AM10/4/17
to elab...@handpoint.com, robotframework-users
Expression syntax supported by Run Keyword If and other similar
keywords is documented in BuiltIn library's docs:
http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Evaluating%20expressions

Cheers,
.peke
> --
> 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.



--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

elab...@handpoint.com

unread,
Oct 5, 2017, 3:46:34 AM10/5/17
to robotframework-users
Sorry to come back about this Pekka, but in that documentation, in the example I can see:
'${status}' == 'PASS'
or
os.sep == '/'

in those examples the spaces are kept.


Elena

Pekka Klärck

unread,
Oct 5, 2017, 4:14:46 AM10/5/17
to elab...@handpoint.com, robotframework-users
2017-10-05 10:46 GMT+03:00 <elab...@handpoint.com>:
> Sorry to come back about this Pekka, but in that documentation, in the
> example I can see:
> '${status}' == 'PASS'
> or
> os.sep == '/'
>
> in those examples the spaces are kept.

Yes. Your problem was not with spaces. It was with quoting.

Cheers,
.peke
Reply all
Reply to author
Forward
0 new messages