Warm tip: This article is reproduced from serverfault.com, please click

Is there any way , I can run keyword by condition checking and ignoring error in robot framework

发布于 2020-12-08 17:42:10

I have a list of variables

${Var1}=     Create List    item1    item2    item3

Now I need to loop through all the elements of the list, only on the particular condition I need to call a particular keyword for others, I will be calling another keyword. Even if the Test case fail in Keyword execution the test must continue

So When we have an item2, I need to call "Check Items". If due to some reason, when we call "Check Items", the keyword fails the execution must NOT stop until all the items in the list are iterated.For others, I will be calling the "Check node" keyword

*** Keywords ***
Check Items
    [Arguments]    ${F}
    Should be Equal     1      ${F}

Check node
    log    ${sample}

I checked with the Run Keyword If Keyword which will help in checking the condition, but the execution is stopping when the keyword fails. With Run Keyword And Ignore Errorwith this, I am not able to check the condition. Please help

Questioner
ashtav
Viewed
0
6,200 2020-12-19 20:10:39

I think that the keyword you are looking for is Run Keyword And Continue On Failure this will return fail if the condition is not satisfied, but the execution will continue.

Keyword Run Keyword And Ignore Error will always be passed, but it also returns the status. You could save this status in var and then evaluate it afterwards. Something like this:

Set Test Variable    ${var}    ${2}
    ${output}=    Run Keyword And Ignore Error     Should Be Equal    ${var}    ${0}

In the output will be stored ('FAIL', '2 != 0')