In Robot Framework, the Exit For Loop If
keyword can be used to terminate a for loop early if a certain condition is met. This keyword takes two arguments: the condition to check and an optional message to log when the condition is true.
Here is an example of using Exit For Loop If
to terminate a for loop:
*** Test Cases ***
Example
@{my_list}= Create List 1 2 3 4 5
FOR ${item} IN @{my_list}
Log to console ${item}
Exit For Loop If ${item} == 3
END
*** Test Cases ***
Example
@{my_list}= Create List 1 2 3 4 5
:FOR ${item} IN @{my_list}
\ Log ${item}
\ Exit For Loop If ${item} == 3
In this example, a list of numbers is created using the Create List
keyword. Then, a for loop is used to iterate over the list. The Log
keyword is used to output each item in the list, and the Exit For Loop If
keyword is used to terminate the loop early if the current item is equal to 3.
If the condition specified in Exit For Loop If
is true, the loop will terminate immediately and no further iterations will be performed. If the condition is false, the loop will continue to iterate normally.
It’s important to note that Exit For Loop If
only works within a for loop. If used outside of a for loop, an error will be raised.
In conclusion, the Exit For Loop If
keyword can be used in Robot Framework to terminate a for loop early if a certain condition is met. This can be useful for optimizing test execution or for handling certain edge cases in your test scenarios.