Looping allows a portion of action logic to execute multiple times. accelQ supports looping with 3 of most commonly known constructs.
Repeat statement
Use this loop when you need to loop for a fixed number of times in the logic. Repetition is unconditional and runs exactly for the given number of times. You can insert a repeat loop by typing "repeat" or "loop" in the new statement.
One of the common examples could be to verify the content of a grid in a page. Here is a snippet of such sample logic.
In the following example, you get the number of rows in the search results grid and verifies a "select" text exists in all rows, in column 3 of the table.
When you create repeat loop, you provide 3 parameters.
- start index for repetition - sets the starting iteration number
- end index for repetition - sets the ending iteration number
- iteration tracker index - sets a variable to track the current iteration number. In the above example, this variable is used to indicate the row number in the table for the verification operation.
While statement
This loop gets repeated based on a stated condition. Differentiate this from repeat loop, which gets executed without any conditions.
When you are creating a while loop, you need to select a condition on which the loop will continue to execute. Once the condition evaluates to false, the loop terminates. In order to make sure this statement does not run into an infinite loop, you will be required to provide the max-loop-count. After this max count, While loop will terminate regardless of the condition evaluating to true or false.
Here is an example. This logic waits incrementally 2 seconds (for a maximum of 120 iterations) as long as the page contains the text, "loading ...".
Do-while statement
This is similar to While loop, except that the condition is evaluated after the logic in the loop block is executed. So, this loop is guaranteed to run atleast one time, as the first iteration is unconditional.
In the case of While loop, the condition gets evaluated before the logic in the loop block is executed.
Max iteration count is similar to While loop to avoid infinite loops.
Comments
0 comments
Article is closed for comments.