Perform while loop in the Selenium IDE

Using the Selenium IDE plugin with Firefox I was able to create a test script that loops through values held in a JavaScript array. I was then able to use each value from the array in a simple test. Below is a brief description on how to perform this task.

First, you’ll need to go out and add a JavaScript extension library to your Selenium IDE to support the while loop. You can find the JavaScript file and a ‘how-to’ here:

http://51elliot.blogspot.com/2008/02/selenium-ide-goto.html

Second, write your test script.  My test is just a quick simple script that will: iterate through a JavaScript array of Twitter account names, log to the Selenium IDE console the account name, open up that account’s Twitter page, and select each accounts following link. The script isn’t very elaborate, but you get the point.

You’ll notice (see below) that the script generously uses the getEval command provided by the Selenium IDE. This command tells the IDE to execute the JavaScript provided in the Target field. I also use the javascript{} notation in the Target field to get at my defined variables.

Here’s a screenshot of what my test looks like in the Selenium IDE:

While Loop In Selenium

While Loop In Selenium

There are certainly other  Selenium commands that could have been used here to accomplish the same thing. Besides the getEval command the Selenium IDE supports a store command for storing variables as well as some short cut notation for getting at those variables. There is also a runScript command that works similar to the getEval command. You’ll need to research those on your own and decide what works best for you.

No comments yet

Leave a reply