Giordano Giuliano
Giordano Giuliano

Reputation: 757

How to loop tests in Selenium IDE?

I've been testing in Selenium IDE. It's pretty easy to use, and I have created some test cases with it. I've been searching Google, trying to find a way to repeat my tests automatically. I've seen a solution with gotolabel, while loops, etc. But I couldn't make any of them works. Can someone give me a tip on how to loop my test n times, or loop forever. I appreciate any help.

Upvotes: 55

Views: 132767

Answers (9)

Simcha Bryzgalov
Simcha Bryzgalov

Reputation: 13

In Selenium IDE Google Chrome. If you use store to assign value to variable, it is not saved like a number, and you need to cast value in js. I saw "solution" on internet without cast and it doesn't work.

store | 0 | counter
while | ${counter} < 5
  echo | Count: ${counter}
  execute script | return Number(${counter}+1) | counter
end

Upvotes: 0

Nicolas Raoul
Nicolas Raoul

Reputation: 60203

No need to install/download anything, the built-in times command does this very easily:

  1. Insert a new line at the beginning of your script, select times as its Command and 10 (for instance) as its Target.
  2. Scroll down to the bottom of your script, and add a new line with end as its command
  3. Press the "Run" button as usual.
  4. Your commands are executed 10 times.

In this example I click on a button 2000 times:

enter image description here

To loop forever, just replace 10 with an extremely large number, that will take centuries to execute, which probably is as good as forever if you are running Selenium IDE.

Upvotes: 60

Al Sargent
Al Sargent

Reputation: 46

Selenium IDE now has flow control. These Control Flow commands work by specifying opening and closing commands to denote a set (or block) of commands.

Available Commands

Here are each of the available control flow commands accompanied by their companion and/or closing commands.

if, else if, else, end times, end do, repeat if while, end

You can read more about it here:

https://www.seleniumhq.org/selenium-ide/docs/en/introduction/control-flow/

Upvotes: 2

Steve HHH
Steve HHH

Reputation: 13147

Use the Flow Control plug-in for Firefox. After restarting Firefox, use the label command to mark a point in the script, and the gotolabel command to jump there.

For example:

enter image description here

Or if you'd rather see the source code, this is a label:

<tr>
    <td>label</td>
    <td>start</td>  
    <td></td>
</tr>

And this causes the execution point to jump back to the label:

<tr>
    <td>gotolabel</td>
    <td>start</td>
    <td></td>
</tr>

There are other commands that you can see on the plug-in page, and documented in the Selenium IDE: Flow Control GitHub project.

Upvotes: 5

Alexandre
Alexandre

Reputation: 11

Your test suite file is just an HTML file, so just do the following:

<tr><td><a href="testCase1.html">testCase1</a></td></tr>
<tr><td><a href="sameStep.html">sameStep</a></td></tr>
<tr><td><a href="testCase2.html">testCase1</a></td></tr>
<tr><td><a href="sameStep.html">sameStep</a></td></tr>

Upvotes: 1

Prashant Vadher
Prashant Vadher

Reputation: 1075

Do this:

  1. Download this js file: https://github.com/darrenderidder/sideflow/blob/master/sideflow.js
  2. Launch Selenium IDE from Firefox and open the options menu.
  3. Upload the .js file to the "Selenium Core extensions (user-extensions.js)" field.

The js file provides goto, gotoIf and while loop functionality in Selenium IDE. The example below shows a simple loop:

<tr>
    <td>getEval</td>
    <td>index = 0;</td>
    <td></td>
</tr>
<tr>
    <td>while</td>
    <td>index &lt; 10;</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>index</td>
    <td>value</td>
</tr>
<tr>
    <td>echo</td>
    <td>${value}</td>
    <td></td>
</tr>
<tr>
    <td>getEval</td>
    <td>index++;</td>
    <td></td>
</tr>
<tr>
    <td>endWhile</td>
    <td></td>
    <td></td>
</tr>

Upvotes: 44

fuzion101
fuzion101

Reputation: 67

I'm new to Selenium (just started using it a few minutes ago). After a quick Google search for "selenium loop" this stackoverflow.com question came up. I immediately jumped into the extension and started using loops. The accepted answer is very helpful. However, I wanted to point out something else for others that are new to selenium (and stumble on this page).

I created a simple test for a simple web page. I added a loop so that the test would run indefinitely (until I paused/stopped it). However, I noticed that by doing this, the Runs/Failures counters within the Selenium GUI do not increment with each loop (I am guessing because a single test case was never running to completion, it was just looping indefinitely). So I dug a bit further. My goal was to leave the same test running for a long time (a few hours, or possibly overnight) to see if there were any failures (I'm chasing an intermittent bug at the moment).

The simplest way (for me, after a few minutes of searching/experimenting) was to do the following (likely no plugins needed, although the attached plugin is definitely helpful if you want to run a few small loops within a test case):

  • save the test case to a text file
  • save the test suite to a text file
  • open the test suite text file in a text editor
  • copy and paste the test case multiple times within the test suite (for example, a thousand times)
  • then open the test suite in Selenium, and run the test suite

Now I have the same simple test suite running many times, and the Runs/Failures counters are incrementing as expected (without the need for any loops).

Upvotes: 5

HelioSilva
HelioSilva

Reputation: 11

This is a sample for sampcop user in order to automate spam complaints using label and goto Label commands:

1st Login on spamcop.net

2nd use Report Spam option

3rd start this script

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://www.spamcop.net/sc" />
<title>testecase</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">testecase</td></tr>
</thead><tbody>

<tr>
    <td>label</td>
    <td>target1</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>link=Report Now</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>//input[@value='Send Spam Report(s) Now']</td>
    <td></td>
</tr>
<tr>
    <td>gotoLabel</td>
    <td>target1</td>
    <td></td>
</tr>
</tbody></table>
</body>
</html>

Upvotes: 1

barry07
barry07

Reputation: 214

as stated in the answer above, install the user extension, which will add loop functionality to Selenium IDE tests. The example below shows a simple loop:

<tr>
<td>getEval</td>
<td>index = 0;</td>
<td></td>
</tr>
<tr>
<td>while</td>
<td>index &lt; 10;</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>index</td>
<td>value</td>
</tr>
<tr>
<td>echo</td>
<td>${value}</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>index++;</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>

Upvotes: 17

Related Questions