How to use "Run Keyword if ${variable} = value?

3,288 views
Skip to first unread message

N.T.

unread,
Jun 29, 2015, 4:02:21 AM6/29/15
to robotframe...@googlegroups.com
For my scripts, I need to be able to switch between running locally or running my scripts through BrowserStack

So I have a variable used to tell the RobotFramework which one to run. called ${ENV}. This is placed in a separate variable file that gets imported 

This is how it's setup on my script:

Run Keyword if ${ENV} == local Open Browser ${url} ${browser}

Run Keyword if ${ENV} == browserstack Open Browser https://localhost:3000 ${browser} remote_url=${COMMAND_BROWSERSTACK} desired_capabilities=${DESIRED_CAPABILITIES_BROWSERSTACK}




When I run my scripts, I get this error:

20150629 16:15:42.785 :  FAIL : Evaluating expression 'browserstack == local' failed: NameError: name 'browserstack' is not defined

Am not quite sure how to fix this. I understand that Python has a different way or reading this scenario but I can't think of a better workaround or how to make this work for me. I need to know how because I might have cases where I can only run certain steps if, say for example am running my script on a mobile environment. So I would say 

Run Keyword if ${mobile} == true

Help is most appreciated as always. Thanks! 


Bryan Oakley

unread,
Jun 29, 2015, 7:11:22 AM6/29/15
to n.to...@iuj.jp, robotframework-users
The expression must be a valid python expression. "browserstack == local" isn't valid unless you have python variables named browserstack and local. Since you're doing string comparisons, you need to add quotes around those values:

    Run Keyword if    "${ENV}" == "local"    Open Browser    ${url}    ${browser}


--
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 http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

N.T.

unread,
Jun 30, 2015, 12:08:18 AM6/30/15
to robotframe...@googlegroups.com, n.to...@iuj.jp
It amazes me how simple the solution was.

It works now. Thanks so much! 


On Monday, June 29, 2015 at 8:11:22 PM UTC+9, Bryan Oakley wrote:
The expression must be a valid python expression. "browserstack == local" isn't valid unless you have python variables named browserstack and local. Since you're doing string comparisons, you need to add quotes around those values:

    Run Keyword if    "${ENV}" == "local"    Open Browser    ${url}    ${browser}


On Mon, Jun 29, 2015 at 3:02 AM, N.T. <n.to...@iuj.jp> wrote:
For my scripts, I need to be able to switch between running locally or running my scripts through BrowserStack

So I have a variable used to tell the RobotFramework which one to run. called ${ENV}. This is placed in a separate variable file that gets imported 

This is how it's setup on my script:

Run Keyword if ${ENV} == local Open Browser ${url} ${browser}

Run Keyword if ${ENV} == browserstack Open Browser https://localhost:3000 ${browser} remote_url=${COMMAND_BROWSERSTACK} desired_capabilities=${DESIRED_CAPABILITIES_BROWSERSTACK}




When I run my scripts, I get this error:

20150629 16:15:42.785 :  FAIL : Evaluating expression 'browserstack == local' failed: NameError: name 'browserstack' is not defined

Am not quite sure how to fix this. I understand that Python has a different way or reading this scenario but I can't think of a better workaround or how to make this work for me. I need to know how because I might have cases where I can only run certain steps if, say for example am running my script on a mobile environment. So I would say 

Run Keyword if ${mobile} == true

Help is most appreciated as always. Thanks! 


--
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-users+unsub...@googlegroups.com.

Wladislaw Wagner

unread,
Jun 30, 2015, 1:28:27 AM6/30/15
to n.to...@iuj.jp, robotframe...@googlegroups.com
Robot Framework just rocks! But some people like my colleague still f**** around with Selenium, Java, Ant, Maven and who knows what else - tryin' to reinvent the f****** wheel!

;-))))))))))


Am Dienstag, 30. Juni 2015 schrieb N.T. :
It amazes me how simple the solution was.

It works now. Thanks so much! 

On Monday, June 29, 2015 at 8:11:22 PM UTC+9, Bryan Oakley wrote:
The expression must be a valid python expression. "browserstack == local" isn't valid unless you have python variables named browserstack and local. Since you're doing string comparisons, you need to add quotes around those values:

    Run Keyword if    "${ENV}" == "local"    Open Browser    ${url}    ${browser}


On Mon, Jun 29, 2015 at 3:02 AM, N.T. <n.to...@iuj.jp> wrote:
For my scripts, I need to be able to switch between running locally or running my scripts through BrowserStack

So I have a variable used to tell the RobotFramework which one to run. called ${ENV}. This is placed in a separate variable file that gets imported 

This is how it's setup on my script:

Run Keyword if ${ENV} == local Open Browser ${url} ${browser}

Run Keyword if ${ENV} == browserstack Open Browser https://localhost:3000 ${browser} remote_url=${COMMAND_BROWSERSTACK} desired_capabilities=${DESIRED_CAPABILITIES_BROWSERSTACK}




When I run my scripts, I get this error:

20150629 16:15:42.785 :  FAIL : Evaluating expression 'browserstack == local' failed: NameError: name 'browserstack' is not defined

Am not quite sure how to fix this. I understand that Python has a different way or reading this scenario but I can't think of a better workaround or how to make this work for me. I need to know how because I might have cases where I can only run certain steps if, say for example am running my script on a mobile environment. So I would say 

Run Keyword if ${mobile} == true

Help is most appreciated as always. Thanks! 


--
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 http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
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.
Reply all
Reply to author
Forward
0 new messages