Parameterization of Tests in Selenium IDE

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.

Comments 15

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

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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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,

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.