Prabodha
Prabodha

Reputation: 670

Read configuration values in robot framework

I have a robot framework test automation product that runs in a docker container. All the configurations for the project are written in a .env file and all works perfectly in the docker environment.

Wat I want is to run this project out side the docker environment(in my laptop using VS code or any other supported IDE). But I don't know how to set the configuration environment when I run the project out side the docker environment.

Can someone please tell me the best way of doing this.

Upvotes: 0

Views: 1003

Answers (1)

Prabodha
Prabodha

Reputation: 670

I found the soultion.

1.You create .env file as below and put all of your environment variables as below. This is the environment file that you are going to push in to the docker container.

HOST_ADDRESS="https://192.168.0.15"
DEFAULT_PORT="8056"

2.Create .yaml file called LocalConfig.yaml and place all your local configuration in that file as below.

LOCAL_HOST_ADDRESS: "https://192.168.0.10"
LOCAL_DEFAULT_PORT: "8055"

3.Create .resource file called Config.resource and read all the environment variables from the OS environment using % character and if the environment variable is not found in the OS, you can set the default value which is defined in the LocalConfig.yml file as below.

*** Settings ***
Variables  LocalConfig.yaml

*** Variables ***
${CONFIG_HOST_ADDRESS}    %{HOST_ADDRESS=${LOCAL_HOST_ADDRESS}}
${CONFIG_PORT}            %{DEFAULT_PORT=${LOCAL_DEFAUL_PORT}}

4.Then you can reference this Config.resource file in any of your .robot files and retrieve the configuration values.

Example:

*** Settings ***
Resource        ../Config.resource

*** Variables ***

*** Test Cases ***
Retrieve env variable Test
Log To Console  ${CONFIG_HOST_ADDRESS}

Upvotes: 1

Related Questions