HomeSelenium

New Selenium IDE – Using ‘do’ and ‘repeat if’ commands

New Selenium IDE – Using ‘do’ and ‘repeat if’ commands

Refer the article New Selenium IDE – Commands (Selenese), for the complete list of Selenium IDE commands and their practical demonstrations.

do and repeat if are the commands in Selenium IDE, which needs to be used together.

do and repeat if are the command in Selenium IDE used for executing a set of same statements multiple times until the repeat if condition becomes false.

Difference between while and  do commands

In while command, the condition to be checked for entering into the iterative loop block will be at the beginning. Whereas in do command, we will check the condition at the end of the iterative loop block using repeat if command. You can understand from the below statements:


while condition

statements inside the while block

end


do

statements inside the do block

repeat if condition


In this article, I will execute a set of statements inside the do block multiple times until the repeat if condition becomes false. i.e. I will execute the same set of statements inside the do block until the value inside the variable x is smaller than 5. Initially, I will assign the value 1 to the variable x and thereafter increment the value stored in variable x by 1 until the repeat if condition becomes false (i.e. when the value of x becomes 5, the repeat if condition x<5 will become false).

The do command will work as depicted below:

do repeat if Selenium IDE - demo

As you can see in the above flow diagram, the block of code inside the do block will be executed multiple times until the repeat if condition becomes false.

Let’s get started.

New Selenium IDE – Using ‘do’ and ‘repeat if’ commands

Follow the below steps for practicing do and repeat if commands in Selenium IDE along with me:

1) Let’s create a test in Selenium IDE for printing the value stored in the variable x until the repeat if condition of do block become false as shown below:

[su_table alternate=”no”]

Command Target Value
open http://omayo.blogspot.com/
execute script return 1 x
do
echo ${x}
execute script return ${x}+1 x
repeat if ${x}<5

[/su_table]

After incorporating the commands in the above table, our Selenium IDE should look like below:

do repeat if Selenium IDE - typing

2) Click on ‘Run current test’ option and observe that the test got successfully executed and the value stored in the variable x will be printed multiple times under the Log tab.

Note: The initial value stored in the variable x is 1 (i.e. we have executed JavaScript statement ‘return 1’ as shown above using execute script command, for storing the value 1 into the variable x)

And also, we have incremented the value stored in the variable x by 1 every time we enter into the while block. (i.e. we have executed JavaScript statement ‘return ${x}+1’ as shown above using execute script command, for incrementing the value stored in the variable by 1 every time we enter to the do block)

do repeat if Selenium IDE - executed

Here concludes the practical demonstration of do and repeat if commands in Selenium IDE.

In the next article, I will practically demonstrate another Selenium IDE command.

Next Steps:

  • > Check complete Selenium Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Arun Motoori

On a mission to contribute to the Software Testing Community in all possible ways.

Refer the article New Selenium IDE – Commands (Selenese), for the complete list of Selenium IDE commands and their practical demonstrations.

Comments (1)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp