How to check environment variable in robot framework?

来源:互联网 发布:合并数组js 编辑:程序博客网 时间:2024/03/28 20:06

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"

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.


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

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


0 0
原创粉丝点击