Selenium Tips: Parametrizing Selenese tests

Posted Mar 12th, 2010

Even though I believe Selenium IDE should just be a transition environment for new Selenium users to reach Selenium RC, we know a lot of our users keep all their tests in Selenese and run them using Selenium IDE as their main testing tool. That's why at Sauce we have developed Sauce IDE, our own extension of Selenium IDE that combines Selenium RC's cross-browser capabilities with the simplicity and interactive design of Selenium IDE.

To continue empowering the IDE users, I'm writing this tip of the week that will help making Selenese tests easier to maintain and write. As you all know, Selenese is not a real programming language. Variable storage in it is pretty rough and there isn't an easy way to share information between different Test Cases in the same Test Suite. However there is a way to do it, through the use of the user-extensions.js file. Let me show you how in two easy steps: First, create a user-extensions.js file with the following content:

storedVars["url"] = "/staging/search";
storedVars["title"] = "Search Your Item";
storedVars["search-string"] = "234234kjkj";

Then open Selenium IDE, or even better Sauce IDE, and in the Options menu, select the file in the "Selenium Core Extensions" field. Close and open Selenium IDE again and you should be ready to use that variable in any test that you write. Even better, throughout your whole test suite. For example:

open ${url}
assertText h1 ${title}
type search-field ${search-string}
click btnSearch
assertTextPresent Search Results for ${search-string}

This may not look super useful at first, but once your test suite grows, keeping things that change from time to time in a single place, makes it really easy to maintain, so if your application's URL changes from "/staging/search" to "/search", you will only need to fix the user-extensions.js file and all the hundreds of tests you could have will pass the same way as they did before.

Check the wikipedia's page on DRY for more information about this programming technique. Hope you found this useful. If you did, please let us know in the comments. Santi

Written by

Santiago Suarez Ordoñez


SeleniumCross-browser testing