【问题标题】:Robot Automation: Continue For Loop even if one test case fails机器人自动化:即使一个测试用例失败也继续循环
【发布时间】:2020-06-30 18:00:15
【问题描述】:

我有一个机器人测试用例,如下图:

*** Test Cases ***
Login Test
    ${jsonfile}    OperatingSystem.Get File   ${EXECDIR}/test/testData/LoginTestData.json
    ${source data}=    Evaluate     json.loads("""${jsonfile}""")    json
    ${all data members}=    Set Variable     ${source data['testcase']}
    FOR    ${member}    IN    @{all data members}
        Keyword 1   ${member} 
        Keyword 2   ${member} 
        .........
        Keyword n   ${member} 
   END

对于任何测试数据,如果任何关键字(例如“关键字 2”)失败,我想停止执行其他关键字(例如关键字 3 到关键字 n)。但是对于其他测试数据,循环应该继续。我怎么能做这个?

【问题讨论】:

    标签: python automated-tests robotframework testautomationfx


    【解决方案1】:

    Run Keyword And Return Status 中运行每个关键字,如果是False,则调用Continue For Loop If 以开始新的迭代:

            ${passed}=    Run Keyword And Return Status  Keyword 1   ${member}
            Continue For Loop If    not ${passed} 
            ${passed}=    Run Keyword And Return Status  Keyword 2   ${member}
            Continue For Loop If    not ${passed}
    

    【讨论】:

    • 您好 Todor,感谢您的回复。关键词多的时候会好看吗?
    【解决方案2】:

    您可以使用Run Keyword ... 系列。例如Run Keyword And Continue On Failure,或Run Keyword And Ignore Error。我经常在这些情况下使用Run Keyword And Return Status

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多