【问题标题】:Robot framework Return value from keyword in for loop is't passed through机器人框架 for 循环中关键字的返回值未通过
【发布时间】:2017-08-09 05:32:48
【问题描述】:

为了测试,我做了 2 个关键字。总体思路是检查一系列对象是否存在某个字段、字段名和消息。如果字段或字段名不存在,则关键字必须返回到 forloop。关键字必须返回${index}${result}。当我运行这个测试并且它失败时,变量 ${results} 显示为${result}=None,当测试通过时它变成${result}= [3, u'PASS']

我认为这与forloop中的${result}=有关

我尝试了Run keyword and return,但它不起作用,我有点困惑将${variables} 放在哪里以及在哪里使用它。 谁能帮我解决这个问题?

FORLOOP:

${index}= |  set variable |   0
${result}= | Set Variable |  not started
: FOR   | ${value} |   IN RANGE |  ${index}  | 15
        \    ${resultaat}= |"other keyword" | ${index} 
        \    ${index}= |   "keyword add 1 to index" |   ${index}
        \    Return From Keyword if  |  '${result}'=='PASS'
${testsuccess}= |  Set Variable If | '${result}'=='PASS' | TEST GESLAAGD

“其他关键字”是:

[ARGS] ${index} 
${index}= | set variable | ${index}
${check1}= <IS FIELD THERE>
${result}= | set variable if | ${check1}==False | FIELD NOT THERE
return from keyword if | ${check1}=False
${check2}= <HAS FIELD VALUE X>
${result}= | set variable if | ${check2}==False | WRONG VALUE
return from keyword if | ${check2}=False
${check3}= <IS MESSAGE X>
${result}= | set variable if | ${check3}==False | FAIL
${result}= | set variable if | ${check3}==True | PASS
[RETURN] ${index} ${result}

日志: 关键字 = '${result}'=='PASS' FOR = '${testsucces}=None'(但这样是不对的,因为条件已经满足了)

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    Set Variable If 将值设置为None,一旦没有任何“Else”选项且不满足条件。见文档:http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Variable%20If

    所以调整你的代码:

    ${result} | Set Variable If | ${check3}==False | FAIL
    ... | ${check3}==True | PASS
    

    如文档示例中所示。

    【讨论】:

    • 谢谢,感谢您的回答,但我正在创建这个测试并且我使用了好的路径。所以结果总是得到满足,因此不是我的问题的解决方案。我会将其添加到我的问题中。但是当我运行测试时,在关键字中设置了变量'${result}'=='PASS',但在FORLOOP中它是None,所以来自关键字的值不会传递给FORLOOP跨度>
    【解决方案2】:

    当我将${result} 放在return from keyword if 之后时,它可以工作

    例如:

    return from keyword if | ${check1}=False | ${result}
    

    【讨论】:

      【解决方案3】:

      在 for 循环中尝试下面的代码返回

      *** Keywords ***
      ReturnFromForLoop
          FOR    ${i}    IN RANGE    1    5
             Return From Keyword    ${i}
          END
      ReturnFromForLoopWithIf
          FOR    ${i}    IN RANGE    1    5
             Return From Keyword If    ${i}==2    ${i}
          END
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-29
        • 2017-07-02
        • 2015-12-08
        • 2016-11-18
        • 1970-01-01
        • 2014-03-07
        • 2017-04-20
        相关资源
        最近更新 更多