Reputation: 613
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"
Upvotes: 4
Views: 9077
Reputation: 613
yes, and another solution is : ${http_proxy}=Get Environment Variable HTTP_PROXY ${EMPTY}
where ${EMPTY} is a user defined variable for default value
Upvotes: 5
Reputation: 385970
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.
Upvotes: 3