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"
yes, and another solution is : ${http_proxy}=Get Environment Variable HTTP_PROXY ${EMPTY}
where ${EMPTY} is a user defined variable for default value
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.
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