According to the docs here
Get Environment Variable (name, default=None)
Returns the value of an environment variable with the given name.
If no such environment variable is set, returns the default value, if given. Otherwise fails the test case.
Returned variables are automatically decoded to Unicode using the system encoding.
Note that you can also access environment variables directly using the variable syntax %{ENV_VAR_NAME}.
I should be able to use
${env_var}= Get Environment Variable STAGING_SERVER
Log To Console ${env_var}
But Robot keeps complaining that there's no such variable. But when I flip over to my terminal and run echo $STAGING_SERVER I get desired output.
What can I do ?
although you pasted docu for "Get Environment Variable" from "OperatingSystem" library you missed a tiny but helpful information:
.... access environment variables directly using the variable syntax %{ENV_VAR_NAME}
So you can easily adapt that in your robot code (eg STAGING_SERVER)
${env_var}= %{STAGING_SERVER}
Log To Console ${env_var}
The variable is not set in the terminal you are using. See this example in Windows command window:
C:\Testes>echo %STAGING_SERVER%
%STAGING_SERVER%
C:\Testes>robot -t env_var Example.robot
==============================================================================
Example
==============================================================================
env var | FAIL |
Environment variable 'STAGING_SERVER' does not exist.
------------------------------------------------------------------------------
Example | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\Testes\output.xml
Log: C:\Testes\log.html
Report: C:\Testes\report.html
C:\Testes>set STAGING_SERVER="The variable is set"
C:\Testes>robot -t env_var Example.robot
==============================================================================
Example
==============================================================================
env var ."The variable is set"
env var | PASS |
------------------------------------------------------------------------------
Example | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\Testes\output.xml
Log: C:\Testes\log.html
Report: C:\Testes\report.html
C:\Testes>echo %STAGING_SERVER%
"The variable is set"
For completeness, this is the test suite:
*** Settings ***
Library OperatingSystem
*** Test Cases ***
env var
${env_var}= Get Environment Variable STAGING_SERVER
Log To Console ${env_var}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With