How can I check an environment variable within a robot?
I have a line:
${http_proxy}= Remove String %{HTTP_PROXY} http://
In my test.txt for robot framework
I would like this suggestion to do well if the HTTP_PROXY environment variable exists. So far, if HTTP_PROXY doesn't exist, it fails like this:
"Environment variable 'HTTP_PROXY' does not exist"
+3
source to share
2 answers
One solution is to use Evaluate to get the value of an environment variable using a method get
in a dictionary os.environ
that allows you to specify a default value:
| | ${HTTP_PROXY}= | Evaluate os.environ.get("HTTP_PROXY", "")
The above will set ${HTTP_PROXY}
to an empty string if the environment variable doesn't exist.
+3
source to share