Selenium IDE doesnt support parametrization but by using some javascript we can parametrize our test case .
Very care fully follow below steps
1.create javascript function "loadTestData" and add this in you extension file user-extensions.js which IDE is pointing.
Copy and paste this code in you user-extensions.js file
/*NAME:
datadriven
PURPOSE: Basic data driven testing.
EXAMPLE USE:
The structure of your data driven test case will be; -------------------------------------------
COMMAND |TARGET |VALUE -------------------------------------------
loadTestData |<file path> | while |!testdata.EOF() |
testcommand1 | | testcommand...| |
testcommandn | | endWhile | |
-------------------------------------------
*/
XML.serialize = function(node) { if (typeof XMLSerializer != "undefined")
return (new XMLSerializer()).serializeToString(node) ; else if (node.xml) return node.xml;
else throw "XML.serialize is not supported or can't serialize " + node;
}
function xmlTestData() {
this.xmlDoc = null; this.testdata = null;
this.index = null;}
xmlTestData.prototype.load = function(xmlloc) {
try { // Internet Explorer.
this.xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); }
catch(e) { // Firefox, Mozilla, Opera, etc.
try { this.xmlDoc = document.implementation.createDocument("","",null);
} catch(e) {
} }
try {
this.xmlDoc.async = false; this.xmlDoc.load(xmlloc);
this.index = 0;
this.testdata = this.xmlDoc.getElementsByTagName("test");
} catch(e) {
}
if (this.testdata == null || this.testdata.length == 0) { throw new Error("Test data couldn't be loaded or test data was empty.");
}}
xmlTestData.prototype.EOF = function() {
if (this.index != null && this.index < this.testdata.length) return false;
return true;}
xmlTestData.prototype.next = function() {
if (this.EOF()) { LOG.error("No test data.");
return; }
LOG.info(XML.serialize(this.testdata[this.index])); // Log should anything go wrong while testing with this data.
if (this.testdata[this.index].attributes.length != this.testdata[0].attributes.length) {
LOG.error("Inconsistent attribute length in test data.");
return; }
for (i=0; i<this.testdata[this.index].attributes.length; i++){
if (null == this.testdata[0].getAttribute(this.testdata[this.index].attributes[i].nodeName)) {
LOG.error("Inconsistent attribute names in test data.");
return; }
selenium.doStore(this.testdata[this.index].attributes[i].nodeValue, this.testdata[this.index].attributes[i].nodeName);
}
this.index++;}
Selenium.prototype.testdata = null;
Selenium.prototype.doLoadTestData = function(xmlloc) {
testdata = new xmlTestData(); testdata.load(xmlloc);
};
Selenium.prototype.doNextTestData = function() { testdata.next();
};
2. Create data file in xml name i.e
googlesearches.xml
with the below contents
<testdata> <test phrase="bbc news"/>
<test phrase="computers"/> <test phrase="mobile phones"/>
<test phrase="insurance & loans"/></testdata>
3. Create test script.
<?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="" /><title>test</title>
</head><body>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">test</td></tr>
</thead><tbody><tr>
<td>loadTestData</td> <td>file:///C:/user/Automation/datadriven/datadriven/googlesearches.xml</td>
<td></td></tr>
<tr> <td>while</td>
<td>!testdata.EOF()</td> <td></td>
</tr><tr>
<td>nextTestData</td> <td></td>
<td></td></tr>
<tr> <td>open</td>
<td>http://www.google.co.in</td>
<td></td></tr>
<tr> <td>type</td>
<td>q</td> <td>${phrase}</td>
</tr><tr>
<td>click</td> <td>btnG</td>
<td></td></tr>
<tr> <td>endWhile</td>
<td></td> <td></td>
</tr>
</tbody></table></body>
</html>
Very carefully update your user-extensions.js or just copy and paste . :)
--
Thanks & Regard,
Niraj Kumar