# 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:** 1\
**Showing post:** 14

<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)**.

---

_[View the full topic](https://forum.robotframework.org/t/how-to-run-robot-tests-on-different-environments-like-dev-qa-prod/4044)._
