机器人自动化:即使一个测试用例失败,也要继续循环



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

*** 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(。但是对于其他测试数据,循环应该继续。我怎么能做这个?

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}

您可以使用Run Keyword ...系列。例如运行关键字并在失败时继续,或者运行关键字并忽略错误。我经常使用运行关键字并返回状态来处理这些情况。

相关内容

最新更新