In Robot Framework, the Continue For Loop If
keyword can be used within a for loop to skip over a particular iteration of the loop if a certain condition is met. This can be useful in cases where you need to skip over certain iterations based on a specific condition.
Here’s an example of how to use the Continue For Loop If
keyword in a for loop:
*** Variables ***
@{list} item1 item2 item3 item4 item5
*** Test Cases ***
Example Test Case
: FOR ${item} IN @{list}
\ Continue For Loop If '${item}' == 'item3'
\ Log ${item}
*** Variables ***
@{list} item1 item2 item3 item4 item5
*** Test Cases ***
Example Test Case
FOR ${item} IN @{list}
Continue For Loop If '${item}' == 'item3'
Log to console ${item}
END
In this example, we have a list of items and we’re using a for loop to iterate through each item in the list. We’re using the Continue For Loop If
keyword to check if the current item is equal to “item3”. If it is, we skip over that iteration and move on to the next one. If the current item is not “item3”, we log the value of the item.
If we run this test case, the output will be:
Example Test Case
item1
item2
item4
item5
As you can see, the “item3” iteration was skipped over due to the Continue For Loop If
keyword.
You can also use the Continue For Loop If
keyword with more complex conditions by using variables and comparison operators. Here’s an example:
*** Variables ***
@{list} item1 item2 item3 item4 item5
${max_length} 4
*** Test Cases ***
Example Test Case
: FOR ${item} IN @{list}
\ ${length}= Get Length ${item}
\ Continue For Loop If ${length} > ${max_length}
\ Log ${item}
*** Variables ***
@{list} item1 item2 item3 item4 item5
${max_length} 4
*** Test Cases ***
Example Test Case
FOR ${item} IN @{list}
${length}= Get Length ${item}
Continue For Loop If ${length} > ${max_length}
Log ${item}
END
In this example, we have a list of items and a variable ${max_length}
that represents the maximum length of an item. We’re using the Get Length
keyword to get the length of each item in the list and store it in the ${length}
variable. We’re then using the Continue For Loop If
keyword to check if the length of the current item is greater than ${max_length}
. If it is, we skip over that iteration and move on to the next one. If the length of the current item is not greater than ${max_length}
, we log the value of the item.
In conclusion, the Continue For Loop If
The keyword in Robot Framework can be used within a for loop to skip over a particular iteration if a certain condition is met. This can be useful in cases where you need to skip over certain iterations based on a specific condition.