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

你离开我真会死。 提交于 2019-12-08 06:15:31

问题


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?


回答1:


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

Set Global Variable    ${MYPROJ_ADMIN_PASSWORD}    supersecret123



回答2:


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

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