Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check environment variable in robot framework?

I have a line:

${http_proxy}=  Remove String  %{HTTP_PROXY}  http://

In my test.txt for robot framework

I'd like this sentence to perform well whether the environ variable HTTP_PROXY is exist. For now, if the HTTP_PROXY is not exist, it will trigger a fail like this:

"Environment variable 'HTTP_PROXY' does not exist"
like image 993
Spirit Avatar asked Feb 13 '23 06:02

Spirit


2 Answers

yes, and another solution is : ${http_proxy}=Get Environment Variable HTTP_PROXY ${EMPTY}

where ${EMPTY} is a user defined variable for default value

like image 195
Spirit Avatar answered Mar 14 '23 22:03

Spirit


One solution is to use Evaluate to get the value of the environment variable using the get method on the os.environ dictionary, which lets you supply a default:

| | ${HTTP_PROXY}= | Evaluate os.environ.get("HTTP_PROXY", "")

The above will set ${HTTP_PROXY} to the empty string if the environment variable doesn't exist.

like image 31
Bryan Oakley Avatar answered Mar 14 '23 23:03

Bryan Oakley