ab.sharma
ab.sharma

Reputation: 190

Robot Automation: Continue For Loop even if one test case fails

I have a robot test case as shown below:

*** 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

For any test data, if any keyword e.g 'Keyword 2' fails, I want to stop executing other keywords(e.g. Keyword 3 to Keyword n). But the loop should continue for other test data. How could I make this?

Upvotes: 0

Views: 1153

Answers (2)

Todor Minakov
Todor Minakov

Reputation: 20047

Run each keyword inside Run Keyword And Return Status and if it's False call Continue For Loop If to start a new iteration:

        ${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}

Upvotes: 1

Helio
Helio

Reputation: 3722

You can use the Run Keyword ... family. For example Run Keyword And Continue On Failure, or Run Keyword And Ignore Error.I often use Run Keyword And Return Status for these cases.

Upvotes: 0

Related Questions