I need to set an variable in testSuite#1. Use the above variable in testSuite#2.
Do we have any keywords to do it? Can we export it at command line?
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.
来源:https://stackoverflow.com/questions/25386974/how-can-we-set-a-variable-such-that-it-can-be-used-in-a-different-test-suite