![](/img/trans.png)
[英]In RobotFramework, how can we use value of one test suite into another test suite in linux?
[英]How can we set a variable such that it can be used in a different test suite?
我需要在 testSuite#1 中設置一個變量。 在 testSuite#2 中使用上述變量。
我們有什么關鍵字可以做到嗎? 我們可以在命令行中導出它嗎?
這不是一個很好的主意,因為您最終會在兩個套件之間產生依賴關系,並且依賴於套件的運行順序。
話雖如此,有幾種方法可以實現這一點。
第一種方法是使用內置庫中的Set Global Variable關鍵字。
| | Set global variable | ${foobar} | this is foobar
第二種方法是使用操作系統庫設置一個可以在兩個套件之間共享的環境變量。
套件1.robot
*** Settings ***
| Library | Operating System
*** Test Case ***
| Save a variable that other suites can see
| | Set environment variable | foobar | this is foobar
套件2.robot
*** Settings ***
| Library | OperatingSystem
*** Test Cases ***
| Use a variable from another suite
| | Should be equal | %{foobar} | this is foobar
請注意使用%
而不是$
來訪問變量。 您還可以使用Get Environment Variable來獲取一個或多個變量的值。
使用 BuiltIn 的Set Global Variable 。 應盡可能避免這種情況,但有時是必要的。
Set Global Variable ${MYPROJ_ADMIN_PASSWORD} supersecret123
檢查下面的代碼示例-
*** Settings ***
Library BuiltIn
*** Test Cases ***
TC1
.....
${test}= ${temp}
Set Global Variable ${test}
TC2
Log to Console \n Global variable value is ${test}
參考: https : //robotframework.org/robotframework/latest/libraries/BuiltIn.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.