Get return value from keyword from within 运行 Keyword If conditional Robot Framework
Get return value from keyword from within Run Keyword If conditional Robot Framework
通常从关键字中获取 return 值没什么大不了的,
${myVar}= My Keyword
这将按预期工作。
我试图解决的问题与以下情况类似。我通常可以找到解决方法,但我想找到更好的方法。
Run Keyword If '${someVar}' == 'True' Run Keywords
... Do Something
... AND ${myVar}= My Keyword
... AND Do More Stuff
当我需要写这样的东西时,My Keyword
关键字不被识别为关键字,我无法 运行 我的测试。我可以将其从条件和 运行 前面的关键字中拉出来,但这意味着我将浪费时间 运行 一个不应该是 运行 的关键字,有时会导致到失败。我找到了 ,但这是针对单个关键字的,我不确定是否可以扩展到多个关键字。此外,其他情况可能会出现以下情况,并且会使事情进一步复杂化,
Run Keyword If '${someVar}' == 'True' Run Keywords
... Do Something
... AND ${myVar}= My Keyword
... AND Do More Stuff
... AND ${myVar_2}= My Other Keyword
... AND Do Other Stuff
有人有什么建议吗?我是否应该将一个 Run Keyword If
分成几个 Run Keyword If
以便我可以利用上面的示例 link?如果有任何建议,我将不胜感激。
更新:
如果其他人遇到此问题,我所做的解决方法如下,
Run Keyword If '${someVar}' == 'True' Do Something
${myVar}= Run Keyword If '${someVar}' == 'True' My Keyword
Run Keyword If '${someVar}' == 'True' Run Keywords
... Do More Stuff
... AND And Do Other More Stuff
我稍后会研究新的 IF
条件,但我想在忘记之前更新它。
您链接到的问题是相同的解决方案,而不是您 运行 一个或多个关键字。
${result}= Run keyword if '${someVar}' Run Keywords ...
在这种情况下,Run Keywords
returns 将分配给 ${result}
。无法在 Run Keywords
.
的参数中进行变量赋值
如果您需要 运行 多个步骤,您可以做的最好的事情是用这些多个步骤创建一个关键字,然后从 Run keyword if
调用该关键字
注:robotframework 4.0(在beta at the time that I read this) supports a native IF statement。据说2020年底发布。原生的IF语句允许你在IF块的body中赋值变量.
有了对 IF
语句的新支持,您可以像这样重写示例:
IF '${someVar}' == 'True'
Do Something
${myVar}= My Keyword
Do More Stuff
${myVar_2}= My Other Keyword
Do Other Stuff
END
通常从关键字中获取 return 值没什么大不了的,
${myVar}= My Keyword
这将按预期工作。
我试图解决的问题与以下情况类似。我通常可以找到解决方法,但我想找到更好的方法。
Run Keyword If '${someVar}' == 'True' Run Keywords
... Do Something
... AND ${myVar}= My Keyword
... AND Do More Stuff
当我需要写这样的东西时,My Keyword
关键字不被识别为关键字,我无法 运行 我的测试。我可以将其从条件和 运行 前面的关键字中拉出来,但这意味着我将浪费时间 运行 一个不应该是 运行 的关键字,有时会导致到失败。我找到了
Run Keyword If '${someVar}' == 'True' Run Keywords
... Do Something
... AND ${myVar}= My Keyword
... AND Do More Stuff
... AND ${myVar_2}= My Other Keyword
... AND Do Other Stuff
有人有什么建议吗?我是否应该将一个 Run Keyword If
分成几个 Run Keyword If
以便我可以利用上面的示例 link?如果有任何建议,我将不胜感激。
更新: 如果其他人遇到此问题,我所做的解决方法如下,
Run Keyword If '${someVar}' == 'True' Do Something
${myVar}= Run Keyword If '${someVar}' == 'True' My Keyword
Run Keyword If '${someVar}' == 'True' Run Keywords
... Do More Stuff
... AND And Do Other More Stuff
我稍后会研究新的 IF
条件,但我想在忘记之前更新它。
您链接到的问题是相同的解决方案,而不是您 运行 一个或多个关键字。
${result}= Run keyword if '${someVar}' Run Keywords ...
在这种情况下,Run Keywords
returns 将分配给 ${result}
。无法在 Run Keywords
.
如果您需要 运行 多个步骤,您可以做的最好的事情是用这些多个步骤创建一个关键字,然后从 Run keyword if
注:robotframework 4.0(在beta at the time that I read this) supports a native IF statement。据说2020年底发布。原生的IF语句允许你在IF块的body中赋值变量.
有了对 IF
语句的新支持,您可以像这样重写示例:
IF '${someVar}' == 'True'
Do Something
${myVar}= My Keyword
Do More Stuff
${myVar_2}= My Other Keyword
Do Other Stuff
END