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:
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:
robot -V qa_env.yaml mytestdir/
Here’s a quick example of what the YAML could look like:
# 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:
*** 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.