我有以下关键字:
App For Port [Arguments] ${app}
# Try to launch one app on either port, continue if it fails on port 1 and launch it on port 2, record if it fails on both.
${returned_port} Set Variable ${1}
: FOR ${port_num} IN 1 2
\ ${returned_port} Set Variable If ${port_num} == 2 ${2}
\ Check App Launch ${app} ${port_num}
Return From Keyword ${returned_port}
${returned_port} Set Variable ${1}
工作正常,此行后${returned_port}
为1。
然而,
${returned_port} Set Variable If ${port_num} == 2 ${2}
给出${returned_port}
无价值。
我真的很困惑。如何设置${returned_port}
为2?在此先感谢!!
答案 0 :(得分:2)
请参阅doc:http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Variable%20If
“第二个值也可以省略,在这种情况下,它的默认值为None。”
这意味着Set Variable If
在第一次循环迭代期间将${returned_port}
设置为None
。
除此之外,您可以稍微简化一下代码:
App For Port
[Arguments] ${app}
: FOR ${port_num} IN 1 2
\ Check App Launch ${app} ${port_num}
......做同样的事。可以?如果您需要在没有条件的情况下从关键字返回值,请使用[Return] ${var}
。
还有一个 - 你可以考虑使用数据驱动的方法:http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#data-driven-style