How to run robot tests on different environments like dev, qa, prod?

Hi,

How to run robot tests on different environments like dev, qa, prod? Please help.

Thanks
Sudheer

Hello @sudheer1987

I have been using nested variables. When I need to use specific environment, only able to call with argument.

Variables:


Nested Variable for call environment from Arguments:

open browser ${url_${environment}} ${browser}

Call with any keyword’s arguments

1 Like

Hi @hrnaltnts,

Can you please explain me more elaborately. My scenario is like I have to launch the specific environment URL in the specified browser based on the input we give from command while running the robot test. Please help.

Thanks,
Sudheer

Take a look at the following example:

*** Variables ***
${ENV}    QA
${QA_URL}    https://qa.example.com/
${DEV_URL}    https://dev.example.com/

*** Test Cases ***
Demo
    Log    ${${ENV}_URL}

By changing ENV variable you could change what url used in test cases.

@JaPyR Thanks for explaining. What if I want to switch to dev environment then how I have to pass that value to the test

You could pass it as command line argument:

robot -v ENV:DEV <rest of arguments>

@Thanks a lot. It’s working. Will develop script further. If I have any queries will get back to you.

@JaPyR What If I have to pass different browsers along with the URL as well

Create a variable for BROWSER, similar to ENV

*** Variables ***
${BROWSER}    Chrome
${ENV}    QA
${QA_URL}    https://qa.example.com/
${DEV_URL}    https://dev.example.com/

*** Test Cases ***
Demo
    Log    ${${ENV}_URL}

Then pass the browser you want in the command line

robot -v BROWSER:Edge -v ENV:DEV <rest of arguments>

Team, related to this. I wanted to use ${ENV} value in IF condition , If it is QA , do some actions if it is DEV , do some actions. When I am comparing I am getting Name error.
Evaluating IF condition failed: Evaluating expression ‘QA == ‘QA’’ failed: NameError: name ‘QA’ is not defined nor importable as module
Could you please help me in this.
I am getting values into init file using CLI , based on above condition I wanted to perform some action.

Quotes.

IF    '${ENV}' == 'QA'
    Do Something
END
1 Like

Hi , Thank you so much. It worked.