是否可以在套件/测试设置中创建新变量 - Robot Framework?
是否可以根据关键字的返回值在套件或测试设置中初始化变量?我试过这种语法,但没有用:
Is it possible to initialize a variable in a suite or test setup based on the return value of a keyword? I've tried this sort of syntax and it didn't work:
*** Settings ***
| Suite Setup | ${A variable}= | Set Variable | A String
我知道我可以调用诸如设置套件变量"之类的关键字,但它们不允许我将变量设置为另一个关键字的结果.我在这个例子中使用了设置变量",但我希望能够在这里调用任何关键字.
I know I can call keywords like "Set Suite Variable" but they don't allow me to set the variable to the result of another keyword. I used "Set Variable" in this example, but I want to be able to call any keyword here.
严格来说,不,这是不可能的.在套件或测试设置中,您只能调用关键字,不能直接在 setup 语句中将变量设置为其他关键字的结果.
Strictly speaking, no, it's not possible. Within a suite or test setup you can only call keywords, you cannot set variables to the result of other keywords directly within the setup statement .
话虽如此,很容易创建一个自定义设置关键字来满足您的需求.例如:
That being said, it's easy to create a custom setup keyword that does what you want. For example:
*** Settings ***
| Suite Setup | Custom suite setup
*** Keywords ***
| Custom suite setup
| | ${A Variable}= | Set Variable | A String
| | Set suite variable | ${A Variable}
上述效果与机器人支持直接在设置中从关键字设置变量的效果相同.而且,当然,您可以调用任何关键字,而不仅仅是 Set Variable
.
The above has the same effect as if robot supported setting variable from keywords directly in the setup. And, of course, you can call any keyword, not just Set Variable
.