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

**URL:** <https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044>\
**Category:** Robot Framework\
**Created:** [22 June 2022 07:12 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044 "2022-06-22T07:12:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudheer1987](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sudheer1987](https://forum.robotframework.org/u/sudheer1987)\
**Post date:** [22 June 2022 07:12 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/1 "2022-06-22T07:12:00Z")

</div>

Hi,

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

Thanks  
Sudheer

---

<div class="post-metadata">

**Author:** ![hrnaltnts](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/hrnaltnts/32/1220_2.png) [@hrnaltnts](https://forum.robotframework.org/u/hrnaltnts)\
**Post date:** [22 June 2022 10:16 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/2 "2022-06-22T10:16:08Z")

</div>

Hello @sudheer1987

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

**Variables:**

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/3/3374e025f5e88abfa4c8aad441bc513e976451de.png)  
**Nested Variable for call environment from Arguments:**

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

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/4/46597ebae9961a295848af7f96d5bedfeaf951cb.png)

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/e/ec0e8b5174f901efd485016632a50af5f0974f5a.png)

**Call with any keyword’s arguments**

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/e/e2386d2781b0bac330a5060db95e517a3a89d80e.png)

---

<div class="post-metadata">

**Author:** ![sudheer1987](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sudheer1987](https://forum.robotframework.org/u/sudheer1987)\
**Post date:** [22 June 2022 12:28 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/3 "2022-06-22T12:28:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JaPyR](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/japyr/32/756_2.png) [@JaPyR](https://forum.robotframework.org/u/JaPyR)\
**Post date:** [23 June 2022 09:04 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/4 "2022-06-23T09:04:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sudheer1987](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sudheer1987](https://forum.robotframework.org/u/sudheer1987)\
**Post date:** [23 June 2022 09:25 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/5 "2022-06-23T09:25:58Z")

</div>

> [@JaPyR](#):
>
> ```python
> ***Variables***
> ${ENV} QA
> ${QA_URL} https://qa.example.com/
> ${DEV_URL} https://dev.example.com/
> 
> ***Test Cases***
> Demo
> Log ${${ENV}_URL}
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![JaPyR](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/japyr/32/756_2.png) [@JaPyR](https://forum.robotframework.org/u/JaPyR)\
**Post date:** [23 June 2022 09:29 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/6 "2022-06-23T09:29:05Z")

</div>

You could pass it as command line argument:

```python
robot -v ENV:DEV <rest of arguments>

```

---

<div class="post-metadata">

**Author:** ![sudheer1987](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sudheer1987](https://forum.robotframework.org/u/sudheer1987)\
**Post date:** [23 June 2022 09:31 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/7 "2022-06-23T09:31:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sudheer1987](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sudheer1987](https://forum.robotframework.org/u/sudheer1987)\
**Post date:** [23 June 2022 09:33 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/8 "2022-06-23T09:33:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [23 June 2022 12:51 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/9 "2022-06-23T12:51:10Z")

</div>

Create a variable for BROWSER, similar to ENV

```python
***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

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

```

---

<div class="post-metadata">

**Author:** ![kiransweng](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@kiransweng](https://forum.robotframework.org/u/kiransweng)\
**Post date:** [29 June 2022 20:16 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/10 "2022-06-29T20:16:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JaPyR](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/japyr/32/756_2.png) [@JaPyR](https://forum.robotframework.org/u/JaPyR)\
**Post date:** [30 June 2022 07:39 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/11 "2022-06-30T07:39:42Z")

</div>

Quotes.

```
IF '${ENV}' == 'QA'
    Do Something
END

```

---

<div class="post-metadata">

**Author:** ![kiransweng](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@kiransweng](https://forum.robotframework.org/u/kiransweng)\
**Post date:** [30 June 2022 14:45 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/12 "2022-06-30T14:45:51Z")

</div>

Hi , Thank you so much. It worked.

---

<div class="post-metadata">

**Author:** ![leorush](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/leorush/32/84_2.png) [@leorush](https://forum.robotframework.org/u/leorush)\
**Post date:** [16 July 2022 22:07 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/13 "2022-07-16T22:07:34Z")

</div>

A more convenient way is to create settings dictionary. And get the key to that dict in the env variable.

---

<div class="post-metadata">

**Author:** ![GLMeece](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/glmeece/32/1553_2.png) [@GLMeece](https://forum.robotframework.org/u/GLMeece)\
**Post date:** [19 July 2022 13:15 UTC](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044/14 "2022-07-19T13:15:46Z")

</div>

My go-to is to create YAML files that encapsulate essential differences between environments. If you focus on _just_ the things that change, then your maintenance load will be lower.

I like YAML because you can represent the 3 primitive data types supported - scalar, list, and dictionary. You’ll need to install **PyYAML** first:

```bash
pip install pyyaml

```

To “slurp up” the variables at runtime, just pass the `-V` switch, along with the path to the YAML file you want to use (you can use relative or absolute paths - I recommend the former). So, for example, if the environment is ‘QA’ and you want to use the file called `qa_env.yaml` at the root of your project, then you’d have a command-line string like this:

```bash
robot -V qa_env.yaml mytestdir/

```

Here’s a quick example of what the YAML could look like:

```nohighlight
# These are scalars:
base_url: https://qaserver.mycompany.com:8080
admin_user: iAmAdMiN
admin_password: eieioscoobydoo1234
# Now, a list:
my_list:
     - Item 1
     - Item two
     - 3
# Finally, a dictionary:
a_dict:
     key_1: A string
     key_2: 1 # an int

```

All the data structures are imported at runtime as the “final say” for variable values. As a super-quick example, to assign them to existing variables at runtime, you’d do something like this:

```nohighlight
***Variables***
${app_url} ${base_url}
@{the_list} @{my_list}
&{the_dict} &{a_dict}

```

Hopefully that all made sense. For the official word on this, see **[Variable file as YAML](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#variable-file-as-yaml)**.
