How can we set a variable such that it can be used in a different test suite?

两盒软妹~` 提交于 2019-12-06 14:46:23

Use BuiltIn's Set Global Variable. This should be avoided whenever possible, but is sometimes necessary.

Set Global Variable    ${MYPROJ_ADMIN_PASSWORD}    supersecret123

This is not a very good idea, because you end up with a dependency between two suites, and a dependency on the order that the suites are run.

That being said, there are a couple of ways you can accomplish this.

Using Set Global Variable

The first method is to use the Set Global Variable keyword from the built-in library.

| | Set global variable | ${foobar} | this is foobar

Setting an environment varible

The second way would be to set an environment variable that can be shared between two suites, using the OperatingSystem library.

suite1.robot

*** Settings ***
| Library | Operating System

*** Test Case ***
| Save a variable that other suites can see
| | Set environment variable | foobar | this is foobar

suite2.robot

*** Settings ***
| Library | OperatingSystem

*** Test Cases ***
| Use a variable from another suite
| | Should be equal | %{foobar} | this is foobar

Notice the use of % instead of $ to access the variable. You can also use Get Environment Variable to get the value of one or more variables.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!