【问题标题】:Python Robot Invalid Return From Keyword usagePython机器人从关键字使用中返回无效
【发布时间】:2016-10-01 18:46:52
【问题描述】:

我正在尝试在 Robot 中执行以下代码并出现以下错误。 我很难找出问题所在

${job_id}=    Run Keyword And Return If    "${cur_build}" != "<my_Build>"    perform software upgrade    ${wd}    <device_name>    <my_build>

下面是xml输出。

Success:  0   Failed :  0   Skipped :  0
 Stop  Delete</msg>
<status status="PASS" endtime="20160602 02:22:51.590" starttime="20160602 02:22:10.415"></status>
</kw>
<msg timestamp="20160602 02:22:51.591" level="INFO">Returning from the enclosing user keyword.</msg>
<status status="PASS" endtime="20160602 02:22:51.591" starttime="20160602 02:22:10.413"></status>

</kw>
<tags>
<tag>draft</tag>
<tag>upgrade</tag>
</tags>
<status status="FAIL" endtime="20160602 02:22:51.592" critical="yes" starttime="20160602 02:21:01.560">Invalid 'Return From Keyword' usage.</status>

编辑

所以我知道 Run Keyword 和 Return if 只能在关键字中使用,而不能在测试用例中使用。但是那我将如何在测试用例中做类似下面的事情

if <some_cond>:
   ${my_var}=    <Keyword A>
   Keyword B=    ${my_var}

一种方法是添加定义新关键字 with 但有没有一种方法可以在测试用例中做到这一点而不定义 anynew 关键字

【问题讨论】:

  • 您的问题不够清楚,请提供更多信息,例如用于解释 .robot 文件的代码。
  • 您发布的代码行必须在用户关键字内。它不能在测试用例、设置或拆卸中。见robotframework.org/robotframework/latest/libraries/…
  • @ombre42 好的,我现在明白了。
  • 现在解决了吗?您是在问“如何根据条件运行关键字并存储返回值?”而不定义新关键字?
  • @Waman 我现在明白为什么我得到了,所以我的问题仍然存在,但是问题陈述现在已经改变,现在就是你提到的。

标签: python robotframework


【解决方案1】:

如果下面的代码符合您的目的,请告诉我

*** Variables ***
@{list1}          @{EMPTY}
@{list2}          This    is    list    list1

*** Test Cases ***
Conditional Test Case1
    ${flag}=    Set Variable If    @{list1}!=@{EMPTY}    ${true}    ${false}
    ${rc}=    Run Keyword If    ${flag}==${true}    Log Multiple Values    ${list1}
    ${rc}=    Run Keyword Unless    ${flag}==${false}    Log Multiple Values    ${rc}

Contitional Test Case2
    ${flag}=    Evaluate    len(${list2}) is not None
    ${rc}=    Run Keyword If    ${flag} == ${true}    Log Multiple Values    ${list2}

*** Keywords ***
Log Multiple Values
    [Arguments]    @{list_args}
    [Documentation]    This keyword logs its arguments and also returns them
    Log Many    @{list_args}
    [Return]    @{list_args}

【讨论】:

  • ${rc}= Run Keyword If ${flag}==${true} Log Multiple Values ${list1} 如果 ${rc} 会热 Log Multiple Values 的返回值,那么这就是我要找的。​​span>
猜你喜欢
  • 2018-12-21
  • 2014-09-11
  • 2018-05-28
  • 2015-01-18
  • 2015-09-23
  • 2014-03-07
  • 1970-01-01
  • 1970-01-01
  • 2017-11-01
相关资源
最近更新 更多