Parameterization of Tests in Selenium IDE

by seetaram on June 30, 2011

Selenium IDE is a Mozilla Firefox add-on which can be utilized to record tests.  These tests can be saved in a folder and executed later in a batch mode.  But the problem we face with this is values such as login username, password, application URL, etc need to be hard coded.  In order to overcome this problem we can store the parameter values in a Javascript file (file.js) and that has to be added to Selenium IDE extension.  In the Selenium Test “storeEval” command should be used to utilize the parameter declared in the .js file.  We will have look at this parameterizing technique in detail.

Create a text file and copy and paste the following code in it.  Then save it as “TestData.js”

searchvar="selenium,selftechy,parameterization"
appurl="http://www.google.co.in"

Open a browser and open the Selenium IDE (here I am taking the liberty of assuming that Selenium IDE is being installed in your system)

SeleniumTestSource

Click on Selenium IDE “options” –> “options”.  This opens up “options” screen, there click on “Browse” button of “Selenium IDE Extensions” and then select the above “TestData.js” file (not GoogleSearch Selenium Test).  After selecting the extension, Selenium IDE needs to be closed and restarted.

Open the Selenium IDE again and click on the Source Tab and that should look as in the above picture.

Now, copy and paste the below code into it and then save it as “GoogleSearch” (File—>Save Test Case As):

<?xml version="1.0" encoding="UTF-8"?>
<!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.google.co.in/" />
<title>SearchGoogle</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">SearchGoogle</td></tr>
</thead><tbody>
<tr>
	<td>storeEval</td>
	<td>searchvar</td>
	<td>searchvar</td>
</tr>
<tr>
	<td>storeEval</td>
	<td>appurl</td>
	<td>appurl</td>
</tr>
<tr>
	<td>storeEval</td>
	<td>sitelink</td>
	<td>sitelink</td>
</tr>
<tr>
	<td>open</td>
	<td>${appurl}</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>q</td>
	<td>${searchvar}</td>
</tr>
<tr>
	<td>click</td>
	<td>btnG</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>q</td>
	<td>qtp forums</td>
</tr>
<tr>
	<td>click</td>
	<td>btnG</td>
	<td></td>
</tr>
</tbody></table>
</body>
</html>

SeleniumTestIDE

After the above is done, click on the “Table” tab and that should look like as in the above picture.

In the above test I have utilized two parameters appurl and searchvar to parameterize the Search terms as well as web site URL.  This is a very much simpler form of parameterization of Selenium Tests.

{ 13 comments… read them below or add one }

christina January 28, 2012 at 4:55 pm

I understand the code but when i tried executing i had a bug sitelink is not defined please help I am new to selenium

Reply

Sri February 16, 2012 at 3:07 pm

Hi Seetaram, I get the same error as Christina…site link not defined. Please can you look into it?

Reply

maala November 8, 2012 at 7:15 am

In order to work the script
delete the following html tags from the code

storeEval
sitelink
sitelink

save it and run the script.

Reply

Priti March 29, 2012 at 4:24 pm

If U delete that particular line of code which stops the execution u would be able to execute it.But it doesnt parametrize it instead it has the steps written twice to get the test executed and make it feel like its parametrised

Reply

Prabhu July 6, 2012 at 6:27 am

Hi Seetaram,
I am unable to solve a problem.Please help me out.My Problem is i have to parameterise the values inside the setup() method instead of hard coding these values i.e)new DefaultSelenium(“localhost”, 5555, “*chrome”, “http://www.google.co.in/”); Any help is appreciated.U can mail me too regarding this.

Thanks in advance
Prabhu

Reply

seetaram July 6, 2012 at 3:51 pm

Prabhu,

Please read the post I have written on parametrization using using properties file

Reply

Prabhu July 10, 2012 at 5:22 am

Hi Seetaram ,

Thanks for ur reply.I went through ur post on parametrization using properties file.In that post i am unable to view the .properties file.Please help me out.Thanks in advance.

Prabhu

Reply

Prabhu July 10, 2012 at 5:59 am

Hi Seetaram,
My problem is i have to start the server outside the junit-selenium testcase .Once the server is started i have to execute the tests using ant .The values of the base url and port number should not be hard coded.I have to parametrize these values.If my question s not clear, i m ready to clarify.Please suggest a method to do this.Any help is appreciated.

Thanks in Advance
Prabhu

Reply

Tammy August 6, 2012 at 2:18 pm

Hello,

Is there a way to execute JS within that file to be able to pull in “today’s date” or “today +10″ into the test script? Would like to have this automated to avoid editing file every time.

Thanks in advance!
Tammy

Reply

Andy August 13, 2013 at 7:52 pm

Hi Seetaram,

Just wanted to give you a big thanks for posting this. I have been looking at parameterizing my tests for quite some time and started to go the WebDriver route prior to coming across your post. This post got me up and running in no time and is going to save me and my team a ton of time configuring our tests for multiple environments with different data sets.

Many thanks!

Andy

Reply

Mohini April 1, 2014 at 2:12 pm

Hi Seetaram,

I am newbie to selenium could you please guide me how to parametrize log-in details using java script and ms-excel.
A log-in page with 6-8 different users access with same/different passwords,after log-in the web content differs for each users.
The requirement is to write those username and password in a excel sheet with the help of java script parametrize it and call in the Selenium IDE.On execution Selenium IDE will call JS having excel parameters to fill the log-in page.
I am familiar with eclipse does the above scenario in easier format but our requirement is different executing from selenium ide.

Regards,

Reply

seetaram April 3, 2014 at 8:25 am

It has already been explained, kindly go through the previous posts

Reply

Mohini April 3, 2014 at 10:03 am

Hi Seetaram,

Yes, I know it can be done through Eclipse-JAVA but what I require is using Selenium IDE with java script calling parameters from excel and users are getting logged.

Regards
Mohini

Reply

Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email