<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;D0IFR3kyeip7ImA9WhRaEUU.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115</id><updated>2012-02-14T07:41:56.792+05:30</updated><category term="Selenium Grid" /><category term="ruby" /><category term="WATIR" /><category term="TestNG" /><category term="EXCEL" /><category term="Code Coverage" /><category term="Firfox Testing Add-on" /><category term="ANT" /><category term="QTP" /><category term="Selenium" /><category term="eclipse" /><category term="Spell Checker" /><category term="Branch Coverage" /><category term="ISTQB Exam Papers" /><category term="CSV" /><category term="JUnit" /><category term="webdriver" /><category term="Handling localizaring in QTP" /><category term="Data Driven" /><category term="ReportNG" /><category term="mics" /><category term="Firefox add-on" /><category term="Line Coverage" /><category term="Cobertura" /><title>Gaurang Shah about Automation</title><subtitle type="html">Contains the tutorial for various automation tools: QTP, Selenium, JUnit, TestNG, ReportNG, ANT, AutoIt, Watir</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://qtp-help.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>57</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/GaurangShahAboutAutomationWithQtp" /><feedburner:info uri="gaurangshahaboutautomationwithqtp" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CEECQHg4eSp7ImA9WhdWEU4.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-9184929644090474414</id><published>2011-09-02T18:08:00.002+05:30</published><updated>2011-09-04T16:07:41.631+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-04T16:07:41.631+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium Grid" /><category scheme="http://www.blogger.com/atom/ns#" term="webdriver" /><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><title>Selenium Grid with Webdriver</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Recently I gone through the webdriver and then I thought to configure it with Selenium grid. On selenium grid site they have mention how to configure it but it's not in details so i though to write that on this blog.&lt;br /&gt;
To configure webdriver with Selenium grid you require grid2. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Prerequisites. &lt;/b&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;TestNG&lt;/li&gt;
&lt;li&gt;Grid2&lt;br /&gt;
Download the selenium-server-standalone-version.jar from the below location.&lt;br /&gt;
&lt;a href="http://code.google.com/p/selenium/downloads/list"&gt;Download Grid2 &lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
We will see two things in Selenium Grid. &lt;br /&gt;
&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;a href="#sameBrowser"&gt;Run Testcase in parallel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#differentbrowser"&gt;Run same testcase on different browser in parallel for browser compatibility testing. &lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;a href="http://www.blogger.com/post-create.g?blogID=1282146880741978115" name="sameBrowser"&gt;&lt;b&gt;Run Testcases in parallel. &lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In this example we will run testcases of GridWithWebdriver and GridWithWebdriver1 class on Internet Explorer. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;GridWithWebdriver.java&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:java"&gt;/**
 * @author Gaurang Shah
 * To Demonstrate how to configure webdirver with Selenium Grid
 */
import java.net.MalformedURLException;
import java.net.URL;

import org.junit.AfterClass;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;

public class GridWithWebdriver {
	
	public WebDriver driver;
	
	@Parameters({"browser"})
	@BeforeClass
	public void setup(String browser) throws MalformedURLException {
		DesiredCapabilities capability=null;
			
		if(browser.equalsIgnoreCase("firefox")){
			System.out.println("firefox");
			capability= DesiredCapabilities.firefox();
			capability.setBrowserName("firefox"); 
			capability.setPlatform(org.openqa.selenium.Platform.ANY);
			//capability.setVersion("");
		}
	
		if(browser.equalsIgnoreCase("iexplore")){
			System.out.println("iexplore");
			capability= DesiredCapabilities.internetExplorer();
			capability.setBrowserName("iexplore"); 
			capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
			//capability.setVersion("");
		}
		
		driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
		driver.navigate().to("http://google.com");
		
	}
	
	@Test
	public void test_first() throws InterruptedException{
		Thread.sleep(3000);
		WebElement search_editbox	=	driver.findElement(By.name("q"));
		WebElement search_button	=	driver.findElement(By.name("btnG"));
		search_editbox.clear();
		search_editbox.sendKeys("first");
		search_button.click();
	}
	
	@Test
	public void test_second(){
		WebElement search_editbox	=	driver.findElement(By.name("q"));
		WebElement search_button	=	driver.findElement(By.name("btnG"));
		search_editbox.clear();
		search_editbox.sendKeys("second");
		search_button.click();
	}
	
	@AfterClass
	public void tearDown(){
        driver.quit();
	}
}
&lt;/pre&gt;&lt;b&gt;GridWithWebdriver1.java&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:java"&gt;/**
 * @author Gaurang Shah
 * To Demonstrate how to configure webdirver with Selenium Grid
 */
import java.net.MalformedURLException;
import java.net.URL;

import org.junit.AfterClass;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;

public class GridWithWebdriver1 {
	
	public WebDriver driver;
	
	@Parameters({"browser"})
	@BeforeClass
	public void setup(String browser) throws MalformedURLException, InterruptedException {
		DesiredCapabilities capability=null;
			
		if(browser.equalsIgnoreCase("firefox")){
			System.out.println("firefox");
			capability= DesiredCapabilities.firefox();
			capability.setBrowserName("firefox"); 
			capability.setPlatform(org.openqa.selenium.Platform.ANY);
			//capability.setVersion("");
		}
	
		if(browser.equalsIgnoreCase("iexplore")){
			System.out.println("iexplore");
			capability= DesiredCapabilities.internetExplorer();
			capability.setBrowserName("iexplore"); 
			capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
			//capability.setVersion("");
		}
		
		driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
		driver.navigate().to("http://google.com");
		
	}
	
	@Test
	public void test_third() throws InterruptedException{
		Thread.sleep(3000);
		WebElement search_editbox	=	driver.findElement(By.name("q"));
		WebElement search_button	=	driver.findElement(By.name("btnG"));
		search_editbox.clear();
		search_editbox.sendKeys("third");
		search_button.click();
		
	}
	
	@Test
	public void test_fourth(){
		WebElement search_editbox	=	driver.findElement(By.name("q"));
		WebElement search_button	=	driver.findElement(By.name("btnG"));
		search_editbox.clear();
		search_editbox.sendKeys("foruth");
		search_button.click();
		
	}
	
	@AfterClass
	public void tearDown(){
        //Close the browser
     //   driver.quit();

	}
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Testng.xml&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;suite name="Selenium Grid with webdriver" verbose="3"  parallel="classes" thread-count="2"&amp;gt;   
  &amp;lt;test name="Selenium Grid Demo"&amp;gt;
  &amp;lt;parameter name="browser" value="iexplore"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="tests.GridWithWebdriver"/&amp;gt;
	  &amp;lt;class name="tests.GridWithWebdriver1"/&amp;gt;
    &amp;lt;/classes&amp;gt;
 &amp;lt;/test&amp;gt;
 &amp;lt;/suite&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Now in order to run using testng.xml we need to start the Grid hub and two remote control with Iexplore as browser. &lt;br /&gt;
&lt;br /&gt;
Now to start the Grid and remote control open CMD and navigate to folder where Grid2 jar (selenium-server-standalone-x.x.x.jar) file is located and use the following commands&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;To start the Grid Hub &lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:plain"&gt;java -jar selenium-server-standalone-2.5.0.jar -role hub&lt;/pre&gt;&lt;b&gt;To start the remote control supporting Internet explore &lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:plain"&gt;java -jar selenium-server-standalone-2.5.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=WINDOWS&lt;/pre&gt;&lt;b&gt;To start another the remote control supporting Internet explore &lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:plain"&gt;java -jar selenium-server-standalone-2.5.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=WINDOWS -port 5556&lt;/pre&gt;&lt;br /&gt;
After this open &lt;a href="http://localhost:4444/grid/console"&gt;http://localhost:4444/grid/console&lt;/a&gt; in you browser. You should be able to see something like below image. &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-v9pOItjqZZY/TmDMRHd8cuI/AAAAAAAAAy0/9Rslgmc2oCo/s1600/grid2_same_browser.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="290" src="http://3.bp.blogspot.com/-v9pOItjqZZY/TmDMRHd8cuI/AAAAAAAAAy0/9Rslgmc2oCo/s400/grid2_same_browser.JPG" width="336" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now if you will run using testng.xml you will see two Internet explorer will open and one will execute test_first() and test_second() while another will execute test_third() and test_fourth() in parallel.&lt;br /&gt;
&lt;br /&gt;
&lt;a name="differentbrowser"&gt;&lt;b&gt;Run same testcases on different browser in parallel. &lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In this example we will execute GridWithWebdriver tests on Firefox and Internet Explorer in parallel. &lt;br /&gt;
&lt;br /&gt;
To do so you need to modify you testng.xml as below. &lt;br /&gt;
&lt;b&gt;Testng.xml&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;suite name="Same TestCases on Different Browser" verbose="3"  parallel="tests" thread-count="2"&amp;gt;   
  &amp;lt;test name="Run on Internet Explorer"&amp;gt;
	&amp;lt;parameter name="browser"  value="iexplore"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="Tests.GridWithWebdriver"/&amp;gt;
    &amp;lt;/classes&amp;gt;
 &amp;lt;/test&amp;gt;  

  &amp;lt;test name="Run on Firefox"&amp;gt;
	&amp;lt;parameter name="browser"  value="firefox"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="Tests.GridWithWebdriver"/&amp;gt;
    &amp;lt;/classes&amp;gt;
 &amp;lt;/test&amp;gt;  
 &amp;lt;/suite&amp;gt;&lt;/pre&gt;Now to run testcases we need to start grid hub and one remote control supporting Firefox and another supporting Internet Explorer. &lt;br /&gt;
&lt;br /&gt;
Now to start the Grid and remote control open CMD and navigate to folder where Grid2 jar (selenium-server-standalone-x.x.x.jar) file is located and use the following commands&lt;br /&gt;
&lt;b&gt;To start the Grid Hub &lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:plain"&gt;java -jar selenium-server-standalone-2.5.0.jar -role hub&lt;/pre&gt;&lt;b&gt;To start the remote control supporting Firefox &lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:plain"&gt;java -jar selenium-server-standalone-2.5.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName=firefox,platform=WINDOWS&lt;/pre&gt;&lt;b&gt;To start another the remote control supporting Internet explore &lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:plain"&gt;java -jar selenium-server-standalone-2.5.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=WINDOWS -port 5556&lt;/pre&gt;After this open &lt;a href="http://localhost:4444/grid/console"&gt;http://localhost:4444/grid/console&lt;/a&gt; in you browser. You should be able to see something like below image. &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Mx1YUE5Awvg/TmDMYzgxdWI/AAAAAAAAAy8/eUZcoGMdwho/s1600/grid2_different_browser.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="290" src="http://3.bp.blogspot.com/-Mx1YUE5Awvg/TmDMYzgxdWI/AAAAAAAAAy8/eUZcoGMdwho/s400/grid2_different_browser.JPG" width="367" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Now if you will run above test case one Firefox and one IE will launch and both test_first() and test_second() will execute in both browser simultaneously.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-9184929644090474414?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MyKHAF8GGzbEqzmRwh2hvjayozA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MyKHAF8GGzbEqzmRwh2hvjayozA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MyKHAF8GGzbEqzmRwh2hvjayozA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MyKHAF8GGzbEqzmRwh2hvjayozA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/i9AGnTvtw9o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/9184929644090474414/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/09/selenium-grid-with-webdriver.html#comment-form" title="11 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/9184929644090474414?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/9184929644090474414?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/i9AGnTvtw9o/selenium-grid-with-webdriver.html" title="Selenium Grid with Webdriver" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-v9pOItjqZZY/TmDMRHd8cuI/AAAAAAAAAy0/9Rslgmc2oCo/s72-c/grid2_same_browser.JPG" height="72" width="72" /><thr:total>11</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/09/selenium-grid-with-webdriver.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEEHR30yeSp7ImA9WhdWEU4.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-2048032123777640312</id><published>2011-08-31T16:29:00.001+05:30</published><updated>2011-09-04T16:07:16.391+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-04T16:07:16.391+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium Grid" /><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><title>Selenium Grid for Browser Compatibility Testing</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;There are two way things we can use Selenium Gird for.&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;To Run our testecases in parallel to save the execution time, as I described in my previous post.&lt;a href="http://qtp-help.blogspot.com/2011/08/selenium-grid.html"&gt;http://qtp-help.blogspot.com/2011/08/selenium-grid.html &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;To test the browser compatibility by running all the testcase in parallel on different browsers. &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
so let's see how to use selenium grid for browser compatibility testing. &lt;br /&gt;
&lt;br /&gt;
There are two way we can make this happen &lt;br /&gt;
&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=1282146880741978115&amp;amp;postID=2048032123777640312#sameMachine"&gt;Using different browsers on same machine. &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=1282146880741978115&amp;amp;postID=2048032123777640312#differentMachine"&gt;Using different browsers on different machines.&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;a href="http://www.blogger.com/post-edit.g?blogID=1282146880741978115&amp;amp;postID=2048032123777640312" name="sameMachine"&gt;&lt;b&gt;Using different browsers on same machine.&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
In this example we will use SeleniumGridDemo.java file, It has two methods test_first() and test_second() which we will execute on Safari and Internet Explorer in parallel.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SeleniumGridDemo.java&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:java"&gt;/**
 * @author Gaurang Shah
 * To demonstrate the Selenium Grid 
 */
import org.testng.annotations.*;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class SeleniumGridDemo {

	public Selenium selenium;

	@Parameters( { "browser" })
	@BeforeClass
	public void setup(String browser) {
		selenium = new DefaultSelenium("localhost", 4444, browser,"http://google.com");
		selenium.start();
	}

	@AfterClass
	public void tearDown() {
		selenium.stop();
	}

	@Test
	public void test_first() {
		selenium.open("/");
		selenium.type("q", "First");
		selenium.click("btnG");
	}

	@Test
	public void test_second() {
		selenium.open("/");
		selenium.type("q", "second");
		selenium.click("btnG");
	}

}
&lt;/pre&gt;&lt;b&gt;testng.xml&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;suite name="Same TestCases on on same machine on different Browser" verbose="3"  parallel="tests" thread-count="2"&amp;gt; 
  &amp;lt;test name="Run on Firefox"&amp;gt;
	&amp;lt;parameter name="browser"  value="*safari"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="SeleniumGridDemo1"/&amp;gt;
    &amp;lt;/classes&amp;gt;
 &amp;lt;/test&amp;gt;
  &amp;lt;test name="Run on IE"&amp;gt;
	&amp;lt;parameter name="browser"  value="*iexplore"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="SeleniumGridDemo1"/&amp;gt;
    &amp;lt;/classes&amp;gt;
 &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;&lt;/pre&gt;&lt;br /&gt;
Now you can run this using eclipse IDE or you can write down the ANT build file as follows. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;build.xml&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;project name="demo" default="run" basedir="."&amp;gt;

 &amp;lt;property name="classes.dir" value="bin" /&amp;gt;
 &amp;lt;property name="src.dir" value="src" /&amp;gt;
 &amp;lt;property name="report.dir" value="reports" /&amp;gt;
 
 &amp;lt;path id="libs"&amp;gt;
  &amp;lt;fileset dir="src\Libs\"&amp;gt;
   &amp;lt;include name="*.jar"/&amp;gt;
  &amp;lt;/fileset&amp;gt;
  &amp;lt;pathelement path="${basedir}\${classes.dir}"/&amp;gt;
 &amp;lt;/path&amp;gt;

 &amp;lt;target name="run"&amp;gt;
  &amp;lt;antcall target="init"/&amp;gt;
  &amp;lt;antcall target="compile"/&amp;gt;
  &amp;lt;antcall target="runTestNG"/&amp;gt;
  &amp;lt;/target&amp;gt;
 
 &amp;lt;!-- Delete old data and create new directories --&amp;gt;
 &amp;lt;target name="init" &amp;gt;
  &amp;lt;echo&amp;gt;Initlizing...&amp;lt;/echo&amp;gt;
  &amp;lt;delete dir="${classes.dir}" /&amp;gt;
  &amp;lt;mkdir dir="${classes.dir}"/&amp;gt;
  &amp;lt;delete dir="${report.dir}" /&amp;gt;
  &amp;lt;mkdir dir="${report.dir}"/&amp;gt;
  &amp;lt;mkdir dir="${logs.dir}"/&amp;gt;
 &amp;lt;/target&amp;gt;

 &amp;lt;!-- Complies the java files --&amp;gt;
 &amp;lt;target name="compile"&amp;gt;
  &amp;lt;echo&amp;gt;Compiling...&amp;lt;/echo&amp;gt;
  &amp;lt;javac debug="true" srcdir="${src.dir}" destdir="${classes.dir}"   classpathref="libs" /&amp;gt;
 &amp;lt;/target&amp;gt;

 &amp;lt;target name="runTestNG"&amp;gt;
 	&amp;lt;taskdef resource="testngtasks" classpathref="libs"/&amp;gt;
	&amp;lt;testng outputDir="${report.dir}" 
			haltonfailure="false"
			useDefaultListeners="true"
			classpathref="libs"&amp;gt;
	&amp;lt;xmlfileset dir="${basedir}" includes="testng.xml"/&amp;gt;
	&amp;lt;/testng&amp;gt;
 &amp;lt;/target&amp;gt;
 &amp;lt;/project&amp;gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Now in order to run testcases in parallel we need to start grid hub and selenium remote controls. As we have specified two threads in testng.xml we will start two remote controls. &lt;br /&gt;
To start grid hub and remote control, Open command prompt, go to selenium grid directory and give following commands. &lt;br /&gt;
&lt;br /&gt;
to stat the grid hub&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-hub&lt;/pre&gt;To Start the selenium remote control for Internet explorer &lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-remote-control -Denvironment=*safari&lt;/pre&gt;To Start the selenium remote control for Internet explorer on different port&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-remote-control -Denvironment=*iexplore -Dport=5556&lt;/pre&gt;&lt;/div&gt;After this open http://localhost:4444/console. In this you should be able to see both the remote controls under Available Remote Controls section as appears in below image.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-FWnkWFtGzq8/Tl4SZtDw-HI/AAAAAAAAAyo/uO7Gh1hgdxo/s1600/SeleniumGrid_SameMachine_DifferentBrowser.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="130" src="http://3.bp.blogspot.com/-FWnkWFtGzq8/Tl4SZtDw-HI/AAAAAAAAAyo/uO7Gh1hgdxo/s400/SeleniumGrid_SameMachine_DifferentBrowser.JPG" width="356" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a href="" name="differentMachine"&gt;&lt;b&gt;Using different browsers on different machines&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
To run the testcases on different machine we don't require to change in testng.xml or java file we just need to start two remote control on two different machines.   &lt;br /&gt;
&lt;br /&gt;
We will start Remote control for safari browser on local machine and for IE browser on remote machine. &lt;br /&gt;
To start grid hub and remote control, Open command prompt, go to selenium grid directory and give following commands. &lt;br /&gt;
&lt;br /&gt;
to stat the grid hub&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-hub&lt;/pre&gt;To Start the selenium remote control for Internet explorer&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-remote-control -Denvironment="*safari"&lt;/pre&gt;&lt;br /&gt;
Now Login into another machine and from command prompt navigate to selenium grid directory and fire following command&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-remote-control -DhubURL=http://172.29.72.185:4444/ -Denvironment=*iexplore&lt;/pre&gt;In above command 172.29.72.185 is the IP address where my Selenium grid Hub is running.&lt;br /&gt;
&lt;br /&gt;
After this open http://localhost:4444/console. In this you should be able to see both the remote controls under Available Remote Controls section as appears in below image. &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-KeJouF_CNpA/Tl4SE2cZq6I/AAAAAAAAAyg/SLYjG4CsQ5c/s1600/SeleniumGrid_DiiferentMachine_DifferentBrowser.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="131" src="http://1.bp.blogspot.com/-KeJouF_CNpA/Tl4SE2cZq6I/AAAAAAAAAyg/SLYjG4CsQ5c/s400/SeleniumGrid_DiiferentMachine_DifferentBrowser.JPG" width="361" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-2048032123777640312?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/w6rBcRJTrOALtvE9LqLw2dCPGK4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w6rBcRJTrOALtvE9LqLw2dCPGK4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/w6rBcRJTrOALtvE9LqLw2dCPGK4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w6rBcRJTrOALtvE9LqLw2dCPGK4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/KksL4KwO-e4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/2048032123777640312/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/08/selenium-grid-for-browser-compatibility.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2048032123777640312?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2048032123777640312?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/KksL4KwO-e4/selenium-grid-for-browser-compatibility.html" title="Selenium Grid for Browser Compatibility Testing" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-FWnkWFtGzq8/Tl4SZtDw-HI/AAAAAAAAAyo/uO7Gh1hgdxo/s72-c/SeleniumGrid_SameMachine_DifferentBrowser.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/08/selenium-grid-for-browser-compatibility.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEYFQn88fip7ImA9WhdXF0w.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-8594545252185697718</id><published>2011-08-29T18:49:00.004+05:30</published><updated>2011-08-30T19:18:33.176+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-30T19:18:33.176+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium Grid" /><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><title>Selenium Grid</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Selenium grid is basically used to run the testcases in parallel. There are two things you can do using selenium grid.&lt;br /&gt;
1. You can run the testcases in parellel to save the execution time. &lt;br /&gt;
2. You can run the same testcases on different browsers in parellel to test for the browser compatibility.&lt;br /&gt;
&lt;br /&gt;
So let's see how to do it.&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Run testcases in parellel&lt;/li&gt;
&lt;ul&gt;&lt;li&gt; &lt;a href="#sameMachine"&gt;Run Testcases of different classes in parallel on same machine.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#differentMachine"&gt;"Run Testcases of different classes in parallel on different machine&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;Run Testcases for browser compatibility&lt;/li&gt;
&lt;ul&gt;&lt;li&gt;Run same testcases on different browser on same machine&lt;/li&gt;
&lt;li&gt; Run same testcases on different browser on different machine&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;
&lt;a name="sameMachine"&gt;Run Testcases of different classes in parallel on same machine.&lt;/a&gt;&lt;br /&gt;
In this example we have to classes SeleniumGridDemo1 and SeleniumGridDemo2. SeleniumGridDemo1 class has two methods test_first() and test_second(). SeleniumGridDemo2 also has two methods test_third() and test_fourth(). &lt;br /&gt;
&lt;br /&gt;
By the following configuration test_first() and test_second() will run in parallel with test_third() and test_fourth(). &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SeleniumGridDemo1.Java&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:java"&gt;/**
 * @author Gaurang Shah
 * To demonstrate the Selenium Grid 
 */
import org.testng.annotations.*;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class SeleniumGridDemo1 {

	public Selenium selenium;

	@Parameters( { "browser" })
	@BeforeClass
	public void setup(String browser) {
		selenium = new DefaultSelenium("localhost", 4444, browser,"http://google.com");
		selenium.start();
	}

	@AfterClass
	public void tearDown() {
		selenium.stop();
	}

	@Test
	public void test_first() {
		selenium.open("/");
		selenium.type("q", "First");
		selenium.click("btnG");
	}

	@Test
	public void test_second() {
		selenium.open("/");
		selenium.type("q", "second");
		selenium.click("btnG");
	}

}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;SeleniumGridDemo2.java&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:java"&gt;/**
 * @author Gaurang Shah
 * To demonstrate the Selenium Grid 
 */
import org.testng.annotations.*;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;


public class SeleniumGridDemo2 {
public Selenium selenium;
	
	@Parameters({"browser"})
	@BeforeClass
	public void setup(String browser){
		selenium = new DefaultSelenium("localhost", 4444, browser, "http://google.com");
		selenium.start();
	}
	
	@AfterClass
	public void tearDown(){
		selenium.stop();
	}
	
	@Test
	public void test_third() { 
		selenium.open("/");
		selenium.type("q","third");
		selenium.click("btnG");
	}	
	@Test
	public void test_fourth() {
		selenium.open("/");
		selenium.type("q","fourth");
		selenium.click("btnG");
	}

}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;TestNG.xml&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;suite name="parelledSuite" verbose="3"  parallel="classes" thread-count="2"&amp;gt;   
  &amp;lt;test name="Selenium Gird Demo"&amp;gt;
  &amp;lt;parameter name="browser" value="*iexplore"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="SeleniumGridDemo1"/&amp;gt;
	  &amp;lt;class name="SeleniumGridDemo2"/&amp;gt;
    &amp;lt;/classes&amp;gt;
 &amp;lt;/test&amp;gt;
 &amp;lt;/suite&amp;gt;&lt;/pre&gt;&lt;br /&gt;
Now in order to run testcases in parallel we need to start grid hub and selenium remote controls. As we have specified two threads in testng.xml we will start two remote controls. &lt;br /&gt;
To start grid hub and remote control, Open command prompt, go to selenium grid directory and give following commands. &lt;br /&gt;
&lt;br /&gt;
to stat the grid hub&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-hub&lt;/pre&gt;To Start the selenium remote control for Internet explorer &lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-remote-control -Denvironment="*iexplore"&lt;/pre&gt;To Start the selenium remote control for Internet explorer on different port&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-remote-control -Denvironment="*iexplore" -Dport=5556&lt;/pre&gt;&lt;br /&gt;
After this open http://localhost:4444/console. In this you should be able to see you both the remote controls under Available Remote Controls section as appears in below image. &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-W5iOrvZPaf8/Tlt9FlnyyRI/AAAAAAAAAyQ/5WLy03YLxxc/s1600/SeleniumGrid_RemoteMachine.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="139" src="http://2.bp.blogspot.com/-W5iOrvZPaf8/Tlt9FlnyyRI/AAAAAAAAAyQ/5WLy03YLxxc/s400/SeleniumGrid_RemoteMachine.JPG" width="376" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now you can run the same using testn.xml from you eclipse any other IDE or you can write down ANT file. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;project name="demo" default="run" basedir="."&amp;gt;

 &amp;lt;property name="classes.dir" value="bin" /&amp;gt;
 &amp;lt;property name="src.dir" value="src" /&amp;gt;
 &amp;lt;property name="report.dir" value="reports" /&amp;gt;
 
 &amp;lt;path id="libs"&amp;gt;
  &amp;lt;fileset dir="src\Libs\"&amp;gt;
   &amp;lt;include name="*.jar"/&amp;gt;
  &amp;lt;/fileset&amp;gt;
  &amp;lt;pathelement path="${basedir}\${classes.dir}"/&amp;gt;
 &amp;lt;/path&amp;gt;

 &amp;lt;target name="run"&amp;gt;
  &amp;lt;antcall target="init"/&amp;gt;
  &amp;lt;antcall target="compile"/&amp;gt;
  &amp;lt;antcall target="runTestNG"/&amp;gt;
  &amp;lt;/target&amp;gt;
 
 &amp;lt;!-- Delete old data and create new directories --&amp;gt;
 &amp;lt;target name="init" &amp;gt;
  &amp;lt;echo&amp;gt;Initlizing...&amp;lt;/echo&amp;gt;
  &amp;lt;delete dir="${classes.dir}" /&amp;gt;
  &amp;lt;mkdir dir="${classes.dir}"/&amp;gt;
  &amp;lt;delete dir="${report.dir}" /&amp;gt;
  &amp;lt;mkdir dir="${report.dir}"/&amp;gt;
  &amp;lt;mkdir dir="${logs.dir}"/&amp;gt;
 &amp;lt;/target&amp;gt;

 &amp;lt;!-- Complies the java files --&amp;gt;
 &amp;lt;target name="compile"&amp;gt;
  &amp;lt;echo&amp;gt;Compiling...&amp;lt;/echo&amp;gt;
  &amp;lt;javac debug="true" srcdir="${src.dir}" destdir="${classes.dir}"   classpathref="libs" /&amp;gt;
 &amp;lt;/target&amp;gt;

 &amp;lt;target name="runTestNG"&amp;gt;
 	&amp;lt;taskdef resource="testngtasks" classpathref="libs"/&amp;gt;
	&amp;lt;testng outputDir="${report.dir}" 
			haltonfailure="false"
			useDefaultListeners="true"
			classpathref="libs"&amp;gt;
	&amp;lt;xmlfileset dir="${basedir}" includes="testng.xml"/&amp;gt;
	&amp;lt;/testng&amp;gt;
 &amp;lt;/target&amp;gt;
 

 &amp;lt;/project&amp;gt;&lt;/pre&gt;&lt;br /&gt;
&lt;a name="differentMachine"&gt;&lt;b&gt;Run Testcases of different classes in parallel on different machine&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
In this example we will run the same testcases in SeleniumGridDemo1 and SeleniumGridDemo2 classes. We don't need to change in testng.xml or any other file.&lt;br /&gt;
&lt;br /&gt;
We just need to start one remote control on local machine and another remote control on another remote machine.  &lt;br /&gt;
&lt;br /&gt;
To start grid hub and remote control, Open command prompt, go to selenium grid directory and give following commands. &lt;br /&gt;
&lt;br /&gt;
to stat the grid hub&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-hub&lt;/pre&gt;To Start the selenium remote control for Internet explorer&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-remote-control -Denvironment="*iexplore"&lt;/pre&gt;&lt;br /&gt;
Now Login into another machine and from command prompt navigate to selenium grid directory and fire following command&lt;br /&gt;
&lt;pre class="brush:plain"&gt;ant launch-remote-control -DhubURL=http://172.29.72.185:4444/ -Denvironment=*iexplore&lt;/pre&gt;In above command 172.29.72.185 is the IP address where my Selenium grid Hub is running.&lt;br /&gt;
&lt;br /&gt;
After this open http://localhost:4444/console. In this you should be able to see both the remote controls under Available Remote Controls section as appears in below image. &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-_S9jmleDBro/TluTQi6khfI/AAAAAAAAAyY/FmSs0JWB-IM/s1600/SeleniumGrid_RemoteMachine.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="122" src="http://3.bp.blogspot.com/-_S9jmleDBro/TluTQi6khfI/AAAAAAAAAyY/FmSs0JWB-IM/s320/SeleniumGrid_RemoteMachine.JPG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-8594545252185697718?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BmqAPiDPfGjY9UYZLIZsqBWmb_U/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BmqAPiDPfGjY9UYZLIZsqBWmb_U/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BmqAPiDPfGjY9UYZLIZsqBWmb_U/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BmqAPiDPfGjY9UYZLIZsqBWmb_U/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/3-6JIKPILYs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/8594545252185697718/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/08/selenium-grid.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/8594545252185697718?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/8594545252185697718?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/3-6JIKPILYs/selenium-grid.html" title="Selenium Grid" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-W5iOrvZPaf8/Tlt9FlnyyRI/AAAAAAAAAyQ/5WLy03YLxxc/s72-c/SeleniumGrid_RemoteMachine.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/08/selenium-grid.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YMRnc4eCp7ImA9WhdQFUs.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-5559646289831509967</id><published>2011-08-03T11:41:00.002+05:30</published><updated>2011-08-17T12:43:07.930+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-17T12:43:07.930+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WATIR" /><category scheme="http://www.blogger.com/atom/ns#" term="Data Driven" /><category scheme="http://www.blogger.com/atom/ns#" term="EXCEL" /><title>WATIR framework</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;What I am going to discuss here is a standard Page Object Pattern Framework for WATIR. &lt;br /&gt;
&lt;br /&gt;
What each and every framework requires are, Driver Script, Object repository, Script to read data from Data source(EXCEL, CSV or any other), Files to generate and store reports and finally Test Files.  &lt;br /&gt;
&lt;br /&gt;
&lt;a href="https://sites.google.com/site/gaurangnshah/Framework.zip"&gt;&lt;b&gt;Download Project&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The framework designed by me contains following things &lt;br /&gt;
&lt;b&gt;Xunit framework&lt;/b&gt; &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;Data Sources&lt;/b&gt;: EXCEL and YAML &lt;br /&gt;
&lt;b&gt;Reports&lt;/b&gt;: I am using ci_reporter with JUnit ANT target to generate HTML report &lt;br /&gt;
&lt;b&gt;Driver Script&lt;/b&gt;: BATCH file which will run tests according to parameter passed and will generate the report. &lt;br /&gt;
&lt;b&gt;Object Repository&lt;/b&gt;: Ruby class per page. &lt;br /&gt;
&lt;br /&gt;
Now let's see everything in details. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Test Script:LoginTestWithYAML.rb inside Test Folder&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:ruby"&gt;require 'rubygems'

gem 'test-unit'
require 'test\unit'
require 'watir'
require 'Libs/BaseClassInstanceMethods'
require 'Libs/BaseClassClassMethods'
require 'ObjRepository/LoginPage'
require 'Libs/ReadYAML'

class LoginTestWithYAML &amp;lt; Test::Unit::TestCase
  include ReadYAML
  include LoginPage
  include BaseClassInstanceMethods
  extend BaseClassClassMethods
  def test_gmail
    username_textbox.set(readData("noPassword","username"))
    password_textbox.set(readData("noPassword","password"))
    login_button.click()
    assert(($browser.text.include? "Enter your password."),"Verify Error Messages")
  end
end&lt;/pre&gt;&lt;b&gt; ReadYAML.rb inside Libs folder&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush:ruby"&gt;require 'yaml'

=begin
Author: Gaurang
read the YAML file based on the given scenario name and fieldname
=end

module ReadYAML
  @@config = YAML.load_file("#{File.dirname(__FILE__)}/../data/gmail.yaml")
  def readData(scenarioName, fieldName)
    if (@@config[scenarioName][fieldName].nil?) then
      return ""
    else
      return @@config[scenarioName][fieldName]
    end

  end
end&lt;/pre&gt;&lt;b&gt; Object repository: LoginPage.rb inside ObjRepository folder &lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush:ruby"&gt;=begin
Author: Gaurang
Contains all the elements on the login page
=end

module LoginPage
  def username_textbox
    return $browser.text_field(:id,"Email")
  end

  def password_textbox
    return $browser.text_field(:id,"Passwd")
  end

  def login_button
    return $browser.button(:id,"signIn")
  end
end&lt;/pre&gt;ANT Target to generate HTML report&lt;br /&gt;
&lt;a href="http://qtp-help.blogspot.com/2011/07/watir-html-report.html"&gt;http://qtp-help.blogspot.com/2011/07/watir-html-report.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;And finally our driver scripts:   run.rb&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush:ruby"&gt;require 'rubygems'
gem 'test-unit'
require 'test/unit'
gem 'ci_reporter'
require 'ci/reporter/rake/test_unit_loader.rb'
=begin
Author: Guarang
Driver file which would run all the tests inside Test Folder.
=end

class Run

  if (ARGV.length &gt;= 1 ) then
    if (ARGV[0].downcase == "smoke") then
      p "smoke"
      folder= "Tests/Smoke/*.rb"
    elsif  (ARGV[0].downcase == "regression") then
      p "regression"
      folder= "Tests/Regression/*.rb"
    end
  else
    p "default"
    folder= "Tests/*.rb"
  end
 
  Dir[folder].each do |test|
    p test
    require test
  end

end&lt;/pre&gt;&lt;b&gt;rub.bat&lt;/b&gt;&lt;br /&gt;
If you want to run all the tests inside Tests\Smoke folder give enter the following command on command prompt &lt;br /&gt;
&lt;b&gt;run smoke&lt;/b&gt; &lt;br /&gt;
for regression enter the following command &lt;br /&gt;
&lt;b&gt;run regression&lt;/b&gt; &lt;br /&gt;
if you will not provide any argument it will run all the tests under Tests folder.&lt;br /&gt;
&lt;pre class="brush:plain"&gt;@echo off 
@echo "initializing..."
rd /s/q Test
@echo "Running Tests..."
ruby run.rb %1
@echo "Generating reports..."
start cmd /C ant
sleep 10
@echo "Opening report..."
start test/reports/junit-noframes.html"
&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-5559646289831509967?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PXquGCUz0WGmbM68uO_ALfTm8Dk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PXquGCUz0WGmbM68uO_ALfTm8Dk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PXquGCUz0WGmbM68uO_ALfTm8Dk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PXquGCUz0WGmbM68uO_ALfTm8Dk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/2klGS5l6Hgw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/5559646289831509967/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/08/watir-framework.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/5559646289831509967?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/5559646289831509967?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/2klGS5l6Hgw/watir-framework.html" title="WATIR framework" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>2</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/08/watir-framework.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C08HQ3kzfCp7ImA9WhdQFkU.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-7233389169719721004</id><published>2011-07-28T23:32:00.001+05:30</published><updated>2011-08-18T21:07:12.784+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-18T21:07:12.784+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="webdriver" /><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><title>WebDriver First look</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;WebDriver has been for a while but never get a chance to look at it. finally today I downloaded the webdriver and executed the simple testcase. Let's see how to configure webdriver for java.&lt;br /&gt;
&lt;br /&gt;
First download the selenium-java-2.2.0.zip (version may differ) from http://code.google.com/p/selenium/downloads/list&lt;br /&gt;
&lt;br /&gt;
The first thing you will notice when you will extract this zip is, too much JAR files, too much as compared to only two in selenium RC. &lt;br /&gt;
&lt;br /&gt;
Now create the simple java project in eclipse. Put all the extracted JAR files in the buildpath of the project. &lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code and run using Junit. (you don't require to run any selenium server)&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:java"&gt;package Tests;

import static org.junit.Assert.assertTrue;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
 * 
 * @author Gaurang
 *
 */
public class GoogleTest  {

 public static WebDriver driver;
 @BeforeClass
 public static void setup(){
 // Create a new instance of the Firefox driver
        driver = new FirefoxDriver();
        
        // And now use this to visit Google
        driver.get("http://www.google.com");
 }
 
 @AfterClass
 public static void tearDown(){
        //Close the browser
        driver.quit();

 }
 @Test
 public void testSearch() throws InterruptedException {
        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));
        // Enter something to search for
        element.sendKeys("Cheese!");
        //driver.findElement(By.name("btnG")).click();
        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();
        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());
        Thread.sleep(3000);
        assertTrue(driver.getTitle().contains("cheese!"));
  }
}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;To run the webdriver testcase in Internet Explorer&lt;/b&gt;&lt;br /&gt;
replace the driver = new FirefoxDriver(); line from the setup() method with following line. &lt;br /&gt;
&lt;pre class="brush:java"&gt;driver = new InternetExplorerDriver();&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;To run the webdriver testcase in Opera &lt;/b&gt;&lt;br /&gt;
replace the driver = new FirefoxDriver(); line from the setup() method with following line. &lt;br /&gt;
&lt;pre class="brush:java"&gt;driver = new OperaDriver();&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;To run the Webdriver testcase in Chrome &lt;/b&gt;&lt;br /&gt;
Download the chrome driver form the below URL &lt;br /&gt;
&lt;a href="http://code.google.com/p/chromium/downloads/list"&gt;Download Chrome driver&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Now extract the zip file and set the path of executable in PATH variable.&lt;br /&gt;
&lt;br /&gt;
replace the driver = new FirefoxDriver(); line from the setup() method with following line. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:java"&gt;driver = new ChromeDriver();&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-7233389169719721004?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/y00Djqo9VvMNNB7rPPMaDRXN0g4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/y00Djqo9VvMNNB7rPPMaDRXN0g4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/y00Djqo9VvMNNB7rPPMaDRXN0g4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/y00Djqo9VvMNNB7rPPMaDRXN0g4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/cZVdOcyoogI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/7233389169719721004/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/07/webdriver-first-look.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/7233389169719721004?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/7233389169719721004?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/cZVdOcyoogI/webdriver-first-look.html" title="WebDriver First look" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/07/webdriver-first-look.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak4GQno8eyp7ImA9WhdSGEs.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-6447536985116544550</id><published>2011-07-28T21:31:00.000+05:30</published><updated>2011-07-28T21:32:03.473+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-28T21:32:03.473+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>Selenium - Handle Alert and Confirmbox</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=1282146880741978115&amp;amp;postID=2758080949163706391" name="handle_alertbox"&gt;Handling alertbox.&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
Alertbox is special kind of modal dialog created though JavaScript.  As it's modal dialog box the things in the parent window will not be accessible until close  it.&lt;br /&gt;
&lt;br /&gt;
selenium has &lt;b&gt;getAlert()&lt;/b&gt;&amp;nbsp; method to handle javascript alertbox, It will click on the OK button of the alertbox and will return the text of the alertbox to verify. However Selenium fails to identify the alertbox if it has appeared through page load event.  ( i.e. should not appeared when you navigate to some page or when refresh it).&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=1282146880741978115&amp;amp;postID=2758080949163706391" name="handle_alertbox_onload"&gt;Handle Alertbox at page load event&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
selenium is not able to indentify the dialogs appeard at the pageload event. look at &lt;a href="http://www.blogger.com/%3Ca%20href=%22http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/java/com/thoughtworks/selenium/DefaultSelenium.html#getAlert%28%29%22%3Ethis%3C/a%3E"&gt;this&lt;/a&gt;.&lt;br /&gt;
So I tried to click on the OK button with AutoIt script. I make the Autoit script, not a big, it's just three lines of code and tested it with both the browser and it did well. But when I call the same script (exe) from my testcase it fails to indentify the alertbox and my testcase failed. I am still finding out why the hell this is happening.&lt;br /&gt;
Following is the script to handle alertbox appeard at body load event.&lt;br /&gt;
&lt;pre class="brush:vb"&gt;AutoItSetOption("WinTitleMatchMode","2")

WinWait($CmdLine[1])
$title = WinGetTitle($CmdLine[1]) ; retrives whole window title
MsgBox(0,"",$title)
WinActivate($title)
WinClose($title);&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%; font-weight: bold;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=1282146880741978115&amp;amp;postID=2758080949163706391" name="handle_confirmbox"&gt;Confirmbox&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
Confirm box is a kind of alertbox with OK and Cancel button as compared to only OK button in alerbox.&lt;br /&gt;
Selenium provides following APIs to handle this.&lt;br /&gt;
&lt;span style="color: #990000;"&gt;chooseOkOnNextConfirmation() &lt;/span&gt;- This will click on the OK button if the confirm box appears after executing the very next  step.&lt;br /&gt;
&lt;span style="color: #990000;"&gt;chooseCancelOnNextConfirmation() &lt;/span&gt;- This will click on the cancel button if the confirm box appears after executing the very next  step.&lt;br /&gt;
&lt;br /&gt;
You need to write down any of the above functions (depends on you requirement, ofcourse) just before the step which opens the confirmbox.&lt;br /&gt;
&lt;pre class="brush:java"&gt;/**
 * @author Gaurang Shah
 * Purpose: To handle Confirm box.
 * Email: gaurangnshah@gmail.com
 */

import org.testng.annotations.*;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class Handle_Alert {
private Selenium selenium;


@BeforeClass
public void startSelenium() {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://gaurangnshah.googlepages.com/");
selenium.start();

}

@AfterClass(alwaysRun=true)
public void stopSelenium() {
this.selenium.stop();
}

@Test
public void handleAlert() throws Exception{
selenium.open("selenium_test");
selenium.click("Alert");
String a = selenium.getAlert();
System.out.println(a);
}

@Test
public void handleConfirmBox() throws Exception {
selenium.open("selenium_test");
selenium.chooseCancelOnNextConfirmation();
selenium.click("Confirm");
}
}&lt;/pre&gt;&lt;a href="http://gaurangnshah.googlepages.com/Handle_Alert.java"&gt;Download above file&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-6447536985116544550?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2bkL3E3CKvF-56S8NXZkGlBV-Cw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2bkL3E3CKvF-56S8NXZkGlBV-Cw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2bkL3E3CKvF-56S8NXZkGlBV-Cw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2bkL3E3CKvF-56S8NXZkGlBV-Cw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/X97FaIfV_K0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/6447536985116544550/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/07/selenium-handle-alert-and-confirmbox.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/6447536985116544550?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/6447536985116544550?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/X97FaIfV_K0/selenium-handle-alert-and-confirmbox.html" title="Selenium - Handle Alert and Confirmbox" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/07/selenium-handle-alert-and-confirmbox.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UGSXo7eyp7ImA9WhdSGEg.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-4292914156818374797</id><published>2011-07-28T17:40:00.000+05:30</published><updated>2011-07-28T17:43:48.403+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-28T17:43:48.403+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WATIR" /><category scheme="http://www.blogger.com/atom/ns#" term="ruby" /><title>Watir - Setup and TearDown</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In Test/Unit framework setup and teardown method invokes before and after each and every tests but sometimes we require to call setup method before test method of the class and teardown method after the last test method of the class. &lt;br /&gt;
&lt;br /&gt;
After searching so much on the internet i found &lt;a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/147656"&gt;this&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In the following example &lt;b&gt;setup&lt;/b&gt; and &lt;b&gt;teardown&lt;/b&gt; method will be called before and after each and every test.&lt;br /&gt;
&lt;b&gt;beforeClass&lt;/b&gt; method will be called before the first test method executes. &lt;br /&gt;
&lt;b&gt;afterClass&lt;/b&gt; method will be called after the last test method executes.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:ruby"&gt;require 'test/unit'

class TestSuite &amp;lt; Test::Unit::TestCase

  def setup
    p 'setup'
  end

  def teardown
    p 'teardown'
  end

  def test1
    p 'test1'
  end

  def test2
    p 'test2'
  end

  def self.suite
    s = super
    def s.beforeClass
      p 'suite_setup'
    end

    def s.afterClass
      p 'suite_teardown'
    end

    def s.run(*args)
      beforeClass
      super
      afterClass
    end
    s
  end
end
&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-4292914156818374797?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LzKdvV8eDiuGQCvZxmM8wS4i6-s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LzKdvV8eDiuGQCvZxmM8wS4i6-s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LzKdvV8eDiuGQCvZxmM8wS4i6-s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LzKdvV8eDiuGQCvZxmM8wS4i6-s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/yY-dw4Abpto" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/4292914156818374797/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/07/watir-setup-and-teardown.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/4292914156818374797?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/4292914156818374797?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/yY-dw4Abpto/watir-setup-and-teardown.html" title="Watir - Setup and TearDown" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/07/watir-setup-and-teardown.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UGSXo7fCp7ImA9WhdSGEg.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-2504586568939813066</id><published>2011-07-26T11:02:00.001+05:30</published><updated>2011-07-28T17:43:48.404+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-28T17:43:48.404+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WATIR" /><category scheme="http://www.blogger.com/atom/ns#" term="ruby" /><category scheme="http://www.blogger.com/atom/ns#" term="Data Driven" /><category scheme="http://www.blogger.com/atom/ns#" term="EXCEL" /><title>WATIR: Parameterization with Excel</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Ruby has already a functionality under win32ole package to make your test data-driven. &lt;br /&gt;
It has functions to read and write data from and to cell. if you need to read the data from a column and 10th row the code will the something like below. &lt;br /&gt;
value = worksheet.Range("a10").Value&lt;br /&gt;
&lt;br /&gt;
However the problem with above code is, when we use that in automation we need to remember what data does "a" column contains, is it username or password or error messages and which scenario does 10th row contain, valid or invalid ?&lt;br /&gt;
&lt;br /&gt;
To get rid of all this question i have write the excel class which will read the data based on given column name(data field name) and row name(scenario name).&lt;br /&gt;
&lt;br /&gt;
The excel file we will access should look like below, where first row should contain data field names and first column should contain scenario names. &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-D8zl1NNheJU/Ti5bGSGrMeI/AAAAAAAAAxk/EX7k2c8exr8/s1600/Watir_Excel_DataDriven.PNG" imageanchor="1"&gt;&lt;img border="0" height="121" src="http://1.bp.blogspot.com/-D8zl1NNheJU/Ti5bGSGrMeI/AAAAAAAAAxk/EX7k2c8exr8/s320/Watir_Excel_DataDriven.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Following is the excel class which will read the data based on given data field name and scenario name&lt;br /&gt;
&lt;b&gt;Excel.rb&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:ruby"&gt;require 'win32ole'

=begin
Purpose: Class to read Excel file given the column name and scenario name
Author:  Gaurang Shah
=end

class Excel

  @@map = Array["a","b","c","d","e","f","g","h","i","j","k","l","m","o","p","q","r","s","t","u","v","w","x","y","z"]
  #provide the path of the EXCEL file.. i.e. c:/demo.xls
  #Provide the worksheet number if you have multiple worksheets
  #If you will not provide the worksheet number by default it will take 1
  def initialize(path, workSheetNumber=1)
    @path=path
    @workSheetNumber=workSheetNumber
  end

  def openExcel
    # puts "inside excel"
    @excel = WIN32OLE::new("excel.Application")

    @workbook = @excel.Workbooks.Open("#{File.dirname(__FILE__)}/#{@path}")

    @worksheet = @workbook.WorkSheets(@workSheetNumber)
    # just to make sure macros are executed, if your sheet doesn't have macros you can skip this step.
    @worksheet.Select

    column = @worksheet.range("a1:a100").Value
    index=0
    while(column[index].to_s != "") do
      index = index+1
    end

    @scenarios = Array.new(index)
    for i in(0...index)do
      @scenarios[i] = column[i]
    end
  end

  #Returns the EXCEL cell value based on provided ScenarioName and columnName
  def getValue(scenarioName,columnName)

    openExcel()
    #get the first line of excel
    columnNames = @worksheet.Rows(1).value[0]

    #Find out the total number of columns
    name=0
    while(columnNames[name+=1] != columnName) do
    end
    #puts name

    begin
      colData = @worksheet.Range("#{@@map[name]}1:#{@@map[name]}100").Value
    rescue
      return "Data Not Found: Invalid Column"
    end

    totalScenarios  = @scenarios.length
    for index in(0..totalScenarios) do
      if(@scenarios[index].to_s == scenarioName) then
        break;
      end
    end

    if(index &amp;gt;= totalScenarios) then
      return "Data Not Found: Invalid Scenario"
    end
    index+=1;

    value = @worksheet.range("#{@@map[name]}#{index}").value
    @workbook.close
    @excel.Quit

    if(value.nil?) then
      return ""
    end
    return value
  end
end
&lt;/pre&gt;&lt;br /&gt;
Following is the sample test which will use the excel class to make test data-driven(parametrized)&lt;br /&gt;
&lt;b&gt;DemoTest.rb&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:ruby"&gt;require 'test/unit'
require 'rubygems'
require 'watir'
require 'Excel'

class DemoTest &amp;lt; Test::Unit::TestCase
  def setup
    @browser = Watir::Browser.new
    @browser.goto("http://gmail.com")
    @browser.maximize
  end

  def test_gmail
    readExcel = Excel.new("gmail.xls")
    puts readExcel.getValue("noPassword","username")
    @browser.text_field(:id,"Email").set(readExcel.getValue("noPassword","username"))
    @browser.text_field(:id,"Passwd").set(readExcel.getValue("noPassword","password"))
    @browser.button(:id,"signIn").click()
    assert((@browser.text.include? "Enter your password."),"Verify Error Messages")
  end

  def teardown
    @browser.close()
  end
end
&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-2504586568939813066?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/AqBpNJiA5UKZDZEyse-M6pzXOm4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AqBpNJiA5UKZDZEyse-M6pzXOm4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/AqBpNJiA5UKZDZEyse-M6pzXOm4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AqBpNJiA5UKZDZEyse-M6pzXOm4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/vlbjNwO3egk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/2504586568939813066/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/07/watir-parameterization-with-excel.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2504586568939813066?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2504586568939813066?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/vlbjNwO3egk/watir-parameterization-with-excel.html" title="WATIR: Parameterization with Excel" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-D8zl1NNheJU/Ti5bGSGrMeI/AAAAAAAAAxk/EX7k2c8exr8/s72-c/Watir_Excel_DataDriven.PNG" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/07/watir-parameterization-with-excel.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04FQXk4fyp7ImA9WhdREEk.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-5030738499591298002</id><published>2011-07-15T14:22:00.002+05:30</published><updated>2011-07-30T21:35:10.737+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-30T21:35:10.737+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WATIR" /><category scheme="http://www.blogger.com/atom/ns#" term="ruby" /><category scheme="http://www.blogger.com/atom/ns#" term="Data Driven" /><category scheme="http://www.blogger.com/atom/ns#" term="EXCEL" /><category scheme="http://www.blogger.com/atom/ns#" term="ReportNG" /><title>WATIR - HTML Report</title><content type="html">I was just evaluating WATIR for one of our project and stuck for some time when it came to report. &lt;br /&gt;
There are ci_reporter gem which generates xml reports, but we required HTML reports. There are various XSL files available on internet which we can use to generate HTML reports out of this XML, I tried that but the reports were not good. We wanted something like generated through ReportNG or Junit. &lt;br /&gt;
&lt;br /&gt;
So I did the trick, I generated JUnit HTML reports from this WATIR XML report file using junitreport ANT Task. &lt;br /&gt;
So let's see how to do it. &lt;br /&gt;
&lt;br /&gt;
First you need to install ci_reporter. use the following command to install it. &lt;br /&gt;
&lt;b&gt;gem install ci_reporter&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:ruby"&gt;require 'test/unit/testcase'
require 'rubygems'
require 'funfx'
require 'ci/reporter/rake/test_unit_loader.rb'


class Demo &amp;lt; Test::Unit::TestCase
 
  def test_first
      assert(true,"PASS");
  end

  def test_second
      assert(false,"Fail");
  end

end  
&lt;/pre&gt;When you will run the above code it will generate the XML report under &lt;b&gt;test\report &lt;/b&gt;folder.   Now to generate the HTML report from this XML file, save the following file as build.xml where your above test file is located.   &lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;project name="Report" default="generateReport" basedir="."&amp;gt;
&amp;lt;property name="report.dir" value="test\reports" /&amp;gt;
&amp;lt;target name="generateReport"&amp;gt;
 &amp;lt;junitreport todir="${report.dir}"&amp;gt;
  &amp;lt;fileset dir="${report.dir}"&amp;gt;
    &amp;lt;include name="*.xml" /&amp;gt;
  &amp;lt;/fileset&amp;gt;
  &amp;lt;report format="noframes" todir="${report.dir}" /&amp;gt;
 &amp;lt;/junitreport&amp;gt;
 &amp;lt;/target&amp;gt;
&amp;lt;/project&amp;gt;&lt;/pre&gt;&lt;br /&gt;
Now run the following command from command line. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ANT &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
But before you run this command ANT need to be installed on your system. Download and install the ANT from following location.&lt;br /&gt;
&lt;a href="http://ant.apache.org/bindownload.cgi"&gt;http://ant.apache.org/bindownload.cgi&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Following is the screenshot of report.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Cz5keYrn0O8/TiAAoE6sHdI/AAAAAAAAAxg/c7EEfFeCCn8/s1600/Sample_WATIR_HTML_Report.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="395" src="http://4.bp.blogspot.com/-Cz5keYrn0O8/TiAAoE6sHdI/AAAAAAAAAxg/c7EEfFeCCn8/s640/Sample_WATIR_HTML_Report.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-5030738499591298002?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2cm22Ho_RsfGEJt8gGnEvXf79Og/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2cm22Ho_RsfGEJt8gGnEvXf79Og/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2cm22Ho_RsfGEJt8gGnEvXf79Og/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2cm22Ho_RsfGEJt8gGnEvXf79Og/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/ndnpwArzZbc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/5030738499591298002/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/07/watir-html-report.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/5030738499591298002?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/5030738499591298002?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/ndnpwArzZbc/watir-html-report.html" title="WATIR - HTML Report" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-Cz5keYrn0O8/TiAAoE6sHdI/AAAAAAAAAxg/c7EEfFeCCn8/s72-c/Sample_WATIR_HTML_Report.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/07/watir-html-report.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8FRX08eip7ImA9WhdTFkk.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-49619444930946152</id><published>2011-07-14T18:20:00.000+05:30</published><updated>2011-07-14T18:20:14.372+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-14T18:20:14.372+05:30</app:edited><title>Selenium with Regular Expression</title><content type="html">&lt;pre class="brush:java"&gt;import static org.junit.Assert.assertTrue;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;


public class SeleniumWithRegex {
 static Selenium selenium;
 @BeforeClass
 public static void setUp() throws Exception {
  selenium = new DefaultSelenium("localhost", 2323, "*chrome", "http://qtp-help.blogspot.com");
  selenium.start();
 }
 /**
  * Verify Text using regular expression
  * @throws InterruptedException
  */
 @Test
 public void verifyText() throws InterruptedException {
  selenium.open("/2010/10/selenium-checkbox-example.html");
  assertTrue(selenium.isTextPresent("regexp:.*gaurang00.*"));
 }
 
 /**
  * Click on button using regular expression
  * @throws InterruptedException
  */
 @Test
 public void testButton() throws InterruptedException {
  selenium.allowNativeXpath("false");
  selenium.click("//input[matches(@id,'Gaurang.*')]");
 }
 
 /**
  * Click on link using regular expression
  * @throws InterruptedException
  */
 @Test
 public void testLink() throws InterruptedException {
   selenium.click("link=regexp:gaurang.*");

 }
 
 @AfterClass
 public static void tearDown(){
  selenium.close();
  selenium.stop();
 }
}

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-49619444930946152?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yGCG3QmrHdSwuoDRpWIM0Zk_RZQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yGCG3QmrHdSwuoDRpWIM0Zk_RZQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yGCG3QmrHdSwuoDRpWIM0Zk_RZQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yGCG3QmrHdSwuoDRpWIM0Zk_RZQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/T6UuMoXHxNw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/49619444930946152/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/07/selenium-with-regular-expression.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/49619444930946152?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/49619444930946152?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/T6UuMoXHxNw/selenium-with-regular-expression.html" title="Selenium with Regular Expression" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/07/selenium-with-regular-expression.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QBSXw-eCp7ImA9WhZVGUQ.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-2935457832731490541</id><published>2011-05-31T12:33:00.001+05:30</published><updated>2011-06-02T11:45:58.250+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T11:45:58.250+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Data Driven" /><category scheme="http://www.blogger.com/atom/ns#" term="CSV" /><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>Selenium - Parameterization with CSV</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Earlier we saw how to write down data driven test cases using Excel file. Using Excel for data driven has it's own advatages like you can write down you function in excel and get rid of programming logic from your test. However to connect to excel you need JDBC connectivity which has it's own overhead in terms of processing time and you always need to remember to close the connection.&lt;br /&gt;
&lt;br /&gt;
In a way using CSV for selenium automation is much faster than Excel. so let's see how to use CVS file with selenium automation. &lt;br /&gt;
&lt;br /&gt;
Save the following data as data.csv. First row is header &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Scenario name,username,password&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;valid,Gaurang,Shah&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;invalid,Gaurang,ccc&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:java"&gt;import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * @author GauranG Shah
 */
public class ReadCSV {
 /**
  * 
  * @param scenarioName - Row Name
  * @param columnName
  * @param fileName - CSV file name where data is stored
  * @return - Sting value
  */
 public String getValue(String scenarioName, String columnName,String fileName){
  
  try {

   // csv file containing data
   String strFile  =  fileName;
   String strLine   =   "";
   StringTokenizer st  =   null;
   int lineNumber   =   0;
  
   // create BufferedReader to read csv file
   BufferedReader br = new BufferedReader(new FileReader(strFile));

   strLine = br.readLine(); //read first line 
   st = new StringTokenizer(strLine, ",");
   int totalRows = st.countTokens();
  
   
   Map&amp;lt;Object,String&amp;gt; mp=new HashMap&amp;lt;Object, String&amp;gt;();
   
   //Fetch the header
   for(int row=0; row&amp;lt;totalRows; row++){
    mp.put(new Integer(row), st.nextToken());
   }
   lineNumber++;

   while ((strLine = br.readLine()) != null){
    st = new StringTokenizer(strLine, ",");
    lineNumber++;
    if(st.nextToken().equalsIgnoreCase(scenarioName)){
     //Identified the row Now return the specific element based on column name specified.
     totalRows= st.countTokens();
     for(int key=1; key&amp;lt;=totalRows; key++){
      String value = st.nextToken();
      if(mp.get(key).equalsIgnoreCase(columnName)){
       return value;
      }
     }
    }
   } 
 
  }catch (Exception e){
   System.out.println("Exception while reading csv file: " + e);
  }
  
  return "Element Not Found";
 }
 
 //This is just to show usage, you can discard this when you use in your project
 public static void main(String[] args) {
  ReadCSV rc = new ReadCSV();
  System.out.println(rc.getValue("valid", "username","data.csv"));
  
 }

}

&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-2935457832731490541?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2izV6jx4FLTZCooyfNwPMWoYyKw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2izV6jx4FLTZCooyfNwPMWoYyKw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2izV6jx4FLTZCooyfNwPMWoYyKw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2izV6jx4FLTZCooyfNwPMWoYyKw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/fH25X6OqkVM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/2935457832731490541/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/05/selenium-parameterization-with-csv.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2935457832731490541?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2935457832731490541?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/fH25X6OqkVM/selenium-parameterization-with-csv.html" title="Selenium - Parameterization with CSV" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/05/selenium-parameterization-with-csv.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QCSXg6eCp7ImA9WhZVGUQ.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-241367472163353547</id><published>2011-05-23T13:15:00.002+05:30</published><updated>2011-06-02T11:46:08.610+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T11:46:08.610+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Data Driven" /><category scheme="http://www.blogger.com/atom/ns#" term="EXCEL" /><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><title>Selenium - Parameterization with EXCEL</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;let's see how to make your selenium test data driven using excel. Using excel as a data driven has it's own advantage. The biggest advantage is it's in a Table format, means easy to understand and modify.   &lt;br /&gt;
Now let's take the simple example of Login test where we have multiple scenarios like Valid Login, Wrong Password, Wrong Username and let's see how we will automate it using selenium and excel.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Ay1xmxyZIdo/TdoR6qNdHLI/AAAAAAAAAwM/VGVuh-8RcJk/s1600/Excel.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-Ay1xmxyZIdo/TdoR6qNdHLI/AAAAAAAAAwM/VGVuh-8RcJk/s1600/Excel.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;span style="color: red;"&gt;Note: Make sue the excel sheet where you write down the data in above format has name "login"&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:java"&gt;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

/**
 * @author Gaurang
 */
public class Excel {

 public static Connection con ;
 
 public static String dbURL =
     "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ= "+ "demo.xls;"
      + "DriverID=22;READONLY=false";
 public static  String  getValueFromExcel(String SheetName, String ColumnName, String Scenario) throws SQLException, ClassNotFoundException {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

  Connection con = DriverManager.getConnection(dbURL);
    
   if(con == null)
    System.out.println("Not able to connect to MS EXCEL");
  Statement stmnt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sFormattedSheetName = "[" + SheetName + "$]";
  SheetName = sFormattedSheetName;
 
  String query = "Select "+ColumnName+" from "+SheetName+" Where TestScenario='"+Scenario+"'" ;
    
  ResultSet rs = stmnt.executeQuery( query );  
  
  rs.next(); //initially cursors is at -1 position
  String value = rs.getString(1);
  rs.close();
  
  return value;
 
 }
 
 @DataProvider(name = "fromExcel")
 public Object[][] createData1() {
  return new Object[][] {
    { "Valid Login" },
    { "Wrong Username"},
    {"Wrong Password"}
  };
 }
 
 @Test(dataProvider="fromExcel")
 public void dataDrivenUsingExcel(String scenarioName) throws SQLException, ClassNotFoundException {
  System.out.println("Scenario="+scenarioName+" UserName="+Excel.getValueFromExcel("login", "UserName", scenarioName));
  System.out.println("Scenario="+scenarioName+" Password="+Excel.getValueFromExcel("login", "Password", scenarioName));
 }
 
}&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-241367472163353547?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/E3Gx118tO6ZqYPLpUBtuf7t6j6c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/E3Gx118tO6ZqYPLpUBtuf7t6j6c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/E3Gx118tO6ZqYPLpUBtuf7t6j6c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/E3Gx118tO6ZqYPLpUBtuf7t6j6c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/OLAfxOPM_e8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/241367472163353547/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/05/selenium-parameterization-with-excel.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/241367472163353547?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/241367472163353547?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/OLAfxOPM_e8/selenium-parameterization-with-excel.html" title="Selenium - Parameterization with EXCEL" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-Ay1xmxyZIdo/TdoR6qNdHLI/AAAAAAAAAwM/VGVuh-8RcJk/s72-c/Excel.JPG" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/05/selenium-parameterization-with-excel.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0QFRH46cCp7ImA9WhZQEEg.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-694857540816828572</id><published>2011-04-17T22:25:00.000+05:30</published><updated>2011-04-17T22:25:15.018+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-17T22:25:15.018+05:30</app:edited><title>Email Testing with Selenium</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;If you web application is sending some emails and if you have to test writing code that opens email client (gmail or yahoo) and then check the mails is tedious and also not reliable. The best thing you can do for this is you can have your own SMTP server, that sends the mail for you and stores any system generated mail, rather than sending to actual user for your testing. The best SMTP server I came across is &lt;b&gt;&lt;a href="http://quintanasoft.com/dumbster/"&gt;Dumbster&lt;/a&gt;&lt;/b&gt;.&lt;/div&gt;&lt;br /&gt;
Now let's see how to use this&lt;br /&gt;
&lt;b&gt;Dumster.java&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:java"&gt;public class Dumbster{
  private SimpleSmtpServer server;

     public Dumbster() {       
       if(server == null)
        server = SimpleSmtpServer.start(25);
     }

     public int howManyMainsSent() {
         int noOfMailsSent = server.getReceivedEmailSize();
         server.stop();          
         return noOfMailsSent;
     }
  
       /**
      * Use only when you are sure only 1 email has been generated
      * @return Subject of the first email
      */
    public String getEmailSubject() {
         Iterator mailIterator = server.getReceivedEmail();
         SmtpMessage email = (SmtpMessage)mailIterator.next();
         return email.getHeaderValue("Subject");
     }
  
     /**
      * Use when more then 1 email has been generated
      * @param count If more than one mails are being generated, Index of the mail
      * @return Subject of the requested email
      */
     public String getEmailSubject(int count) {
          Iterator mailIterator = server.getReceivedEmail();
          SmtpMessage email = null;
          for(int i=1; i&lt;=count; i++){
            email = (SmtpMessage)mailIterator.next();
          }
          return email.getHeaderValue("Subject");
      }
}&lt;/pre&gt;
&lt;/div&gt;&lt;br /&gt;
Now to use Test the mail you just need to create the server of this class just before you mails shoots and then you need to call the particular function you want.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-694857540816828572?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ypca5HqJp1OecSAtArJWdIiI1UQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ypca5HqJp1OecSAtArJWdIiI1UQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ypca5HqJp1OecSAtArJWdIiI1UQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ypca5HqJp1OecSAtArJWdIiI1UQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/pa7k9Ll808I" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/694857540816828572/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/04/email-testing-with-selenium.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/694857540816828572?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/694857540816828572?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/pa7k9Ll808I/email-testing-with-selenium.html" title="Email Testing with Selenium" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/04/email-testing-with-selenium.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QNSHozcSp7ImA9WhZVGUQ.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-2500934963746805766</id><published>2011-04-12T12:38:00.002+05:30</published><updated>2011-06-02T11:46:39.489+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T11:46:39.489+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium Grid" /><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>Selenium Grid with JUnit</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I just tried my hands on Selenium Grid few days back as our tests were taking too much time to execute, almost 5 hours if we run all and so we thought to use Selenium Grid to cut down the time.&amp;nbsp; I downloaded the Selenium Gid, run the demo and it all went well until I come to know that your framework should also support parallel execution if you want to run multiple test parallel using Grid. And the problem was JUnit doesn't provided parallel execution. One more reason why you should use TestNG...&lt;br /&gt;
&lt;br /&gt;
There is solution where you can write your own class to parallelize the JUnit testcases&amp;nbsp; or better download from the Internet. There are so many available. But I found the another and bit easy way. &lt;br /&gt;
&lt;br /&gt;
You can use the ANT parallel task to achieve this parallelism. Following is the demo which shows how to execute testcases parallel with Selenium Grid and JUnit.&lt;br /&gt;
&lt;b&gt;&lt;a href="https://sites.google.com/site/gaurangnshah/Selenium_Grid_With_JUnit.zip"&gt;Download the demo&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;&lt;li&gt;Download the selenium gird from &lt;a href="http://selenium-grid.seleniumhq.org/download.html"&gt;here&lt;/a&gt; and extract it into some folder&lt;/li&gt;
&lt;li&gt;Now navigate to extracted folder through command prompt and type following command&lt;br /&gt;
&lt;b&gt;ant launch-hub&lt;/b&gt;&lt;br /&gt;
This will launch the hub on port 4444, this is the port where your selenium tests need to connect.&lt;/li&gt;
&lt;li&gt;Now you need to launch the remote control.type the following command on command prompt&lt;br /&gt;
&lt;b&gt;ant launch-remote-control&lt;/b&gt;&lt;br /&gt;
This will launch the remote control on port 5555.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Now we have launched one remote control, we will launch another remote control on port 5556. So one class will execute all it's test on remote control running on 5555 and another class will run it's testcases on remote control running on 5556. Type the following command to launch the remote control on 5556 port.&lt;br /&gt;
&lt;b&gt;ant launch-remote-control -Dport=5556&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;Now we have two remote control running on the same machine we need to run testcases.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;demo1.java&lt;br /&gt;
&lt;pre class="brush:java"&gt;import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

/**
 * @author Gaurang
 */
public class demo1 {
 Selenium selenium;

 @Before
 public void setUp() throws Exception {
  selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.co.in/");
  selenium.start();
  selenium.setTimeout("6000");
 }
 
 @Test
 public void test_1() throws Exception {
  System.out.println("1");
  selenium.open("/");
  selenium.type("q", "1");
 }
 @Test
 public void test_2() throws Exception {
  System.out.println("2");
  selenium.open("/");
  selenium.type("q", "2");
 }

 @After
 public void tearDown() throws Exception {
   selenium.stop();
 }
}
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;demo2.java&lt;br /&gt;
&lt;pre class="brush:java"&gt;import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

/**
 * @author Gaurang
 */
public class demo2 {
 Selenium selenium;

 @Before
 public void setUp() throws Exception {
  selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.co.in/");
  selenium.start();
  selenium.setTimeout("6000");
 }
 
 @Test
 public void test_3() throws Exception {
  System.out.println("3");
  selenium.open("/");
  selenium.type("q", "3");
 }
 @Test
 public void test_4() throws Exception {
  selenium.open("/");
  selenium.type("q", "4");
 }
  
 @After
 public void tearDown() throws Exception {
   selenium.stop();
 }
}
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Build.xml&lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;project name="demo" default="run" basedir="."&amp;gt;
 &amp;lt;path id="lib.classpath"&amp;gt;
  &amp;lt;fileset dir="lib"&amp;gt;
   &amp;lt;include name="*.jar" /&amp;gt;
  &amp;lt;/fileset&amp;gt;
  &amp;lt;pathelement location="bin" /&amp;gt;
 &amp;lt;/path&amp;gt;
 
 &amp;lt;target name="run" depends="compile"&amp;gt;
  &amp;lt;parallel threadCount='4'&amp;gt;
   &amp;lt;junit printsummary="withOutAndErr" haltonfailure="no"&amp;gt;
    &amp;lt;formatter type="xml" usefile="true" /&amp;gt;
    &amp;lt;classpath refid="lib.classpath" /&amp;gt;
    &amp;lt;batchtest fork="true" todir="results" failureproperty="seleniumTests.failed" errorproperty="seleniumTests.failed"&amp;gt;
     &amp;lt;fileset dir="bin"&amp;gt;
      &amp;lt;include name="demo1.class" /&amp;gt;
     &amp;lt;/fileset&amp;gt;
    &amp;lt;/batchtest&amp;gt; 
   &amp;lt;/junit&amp;gt;
  
  
   &amp;lt;junit printsummary="withOutAndErr" haltonfailure="no"&amp;gt;
   &amp;lt;formatter type="xml" usefile="true" /&amp;gt;
   &amp;lt;classpath refid="lib.classpath" /&amp;gt;
   &amp;lt;batchtest fork="true" todir="results" failureproperty="seleniumTests.failed" errorproperty="seleniumTests.failed"&amp;gt;
    &amp;lt;fileset dir="bin"&amp;gt;
     &amp;lt;include name="demo2.class" /&amp;gt;
    &amp;lt;/fileset&amp;gt;
   &amp;lt;/batchtest&amp;gt; 
   &amp;lt;/junit&amp;gt;
  &amp;lt;/parallel&amp;gt;
 &amp;lt;/target&amp;gt;
 
 &amp;lt;target name="compile"&amp;gt;
 &amp;lt;echo&amp;gt; compiling.....&amp;lt;/echo&amp;gt;
  &amp;lt;javac srcdir="src" destdir="bin" classpathref="lib.classpath" /&amp;gt;
 &amp;lt;/target&amp;gt;
&amp;lt;/project&amp;gt;&lt;/pre&gt;&lt;pre class="brush:xml"&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt; Now you run the testcases using build.xml file. Use the following command to run the testcases.&lt;br /&gt;
&lt;b&gt;ant run&lt;/b&gt;&lt;br /&gt;
This will run demo1.class and demo2.class in parellel. &lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-2500934963746805766?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hDENz3CNuj_CUZVfT6nbPF1sjEo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hDENz3CNuj_CUZVfT6nbPF1sjEo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hDENz3CNuj_CUZVfT6nbPF1sjEo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hDENz3CNuj_CUZVfT6nbPF1sjEo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/Q5ih8pBSUVw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/2500934963746805766/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/04/selenium-grid-with-junit.html#comment-form" title="10 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2500934963746805766?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2500934963746805766?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/Q5ih8pBSUVw/selenium-grid-with-junit.html" title="Selenium Grid with JUnit" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>10</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/04/selenium-grid-with-junit.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YMSXc4fCp7ImA9WhZSFEo.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-3198677978494993514</id><published>2011-03-29T18:53:00.002+05:30</published><updated>2011-03-30T14:23:08.934+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-30T14:23:08.934+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><title>selenium Timed out after 30000ms error</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;"Timed out after 30000ms error" is one of the most frequent error of selenium. However the solution of this is very simple, but before we look into it let's see why we are getting this error. &lt;br /&gt;
&lt;br /&gt;
Mostly this error appears after the following statement&lt;br /&gt;
selenium.waitForPageToLoad("30000");&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Now let's see why it comes. &lt;/b&gt;&lt;br /&gt;
waitForPageToLoad(timeout) API says that, it will wait for the giving timeout and if page hasn't loaded withing that time it will return error. and so there are two reason it returns error.&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;timeout given is less that what it requires to load the page&lt;/li&gt;
&lt;li&gt;page is not loading at all, it's just a AJAX call and only part of the page is being updated.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;Now let's see the solultion. &lt;/b&gt;&lt;br /&gt;
The best solution for this is not to use waitForPageToLoad API, rather to wait for some specific element on the page to appear.&lt;br /&gt;
&lt;br /&gt;
For example I am rather than waiting for the google page to load I am waiting until the searchbox is visible. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:java"&gt;//Wait until searchbox appears or 3 min
waitForElementPresent("q",3); 
/**
  * @author Gaurang
  * @param xpath
  * @param timeout (minutes)
  * @throws InterruptedException
  * @return returns true if element found in given time else false
  *  Wait for specified time till specific element is not present 
  */
 public boolean waitForElementPresent(String xpath, int timeout) throws InterruptedException{
  int count = 0;
  while(selenium.isElementPresent(xpath) != true){
   Thread.sleep(10*1000); //Wait 10 seconds
   if(count++ &amp;gt; timeout*6 ) break;
  }
  
  if(selenium.isElementPresent(xpath))
   return true;
  else
   return false;
    
 }
&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-3198677978494993514?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/T88ADa71n40fXE_geowYFX4dfs8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/T88ADa71n40fXE_geowYFX4dfs8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/T88ADa71n40fXE_geowYFX4dfs8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/T88ADa71n40fXE_geowYFX4dfs8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/N6EnAwWhoL4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/3198677978494993514/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/03/selenium-timed-out-after-30000ms-error.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/3198677978494993514?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/3198677978494993514?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/N6EnAwWhoL4/selenium-timed-out-after-30000ms-error.html" title="selenium Timed out after 30000ms error" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/03/selenium-timed-out-after-30000ms-error.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YMSXc4fSp7ImA9WhZSFEo.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-362339532666760356</id><published>2011-03-16T18:46:00.003+05:30</published><updated>2011-03-30T14:23:08.935+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-30T14:23:08.935+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><title>Selenium with Flex</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Recently I just got the chance to check the selenium support with Flex. And after few minutes spending on google I finally find almost everything required for to test flex application. &lt;br /&gt;
To provide flex support to selenium is easy, you just need to add few more JAR files but there is a minor problmes too. &lt;br /&gt;
&lt;ol style="text-align: left;"&gt;&lt;li&gt;You require your developers to rebuild your application with provided library file (SeleniumFlexAPI.swc) by selenium flex&lt;/li&gt;
&lt;li&gt;It's not working with Firefox 3.0 or greater version (at least it didn't work with me !!, I am still searching for the solution)&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
Now let's see how to test flex application with selenium step by step.&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;b&gt;Rebuild your flex application&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Download the zip file from &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=228427"&gt;here&lt;/a&gt; and extract the zip file&lt;/li&gt;
&lt;li&gt;In FlexBuilder, add the SeleniumFlexAPI.swc in the /src folder, then build your application with -include-libraries SeleniumFlexAPI.swc as the additional compiler argument &lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Include the JAR files in the the project&lt;/b&gt;&lt;/li&gt;
Before you began coding you require following jar files in your build in addition to selenium-java-client-driver.jar &lt;br&gt;&lt;a href="http://code.google.com/p/flash-selenium/downloads/list"&gt;flashselenium-java-client-extension.jar&lt;/a&gt;&lt;br&gt; &lt;a href="http://code.google.com/p/flex-ui-selenium/downloads/list"&gt;flex-ui-selenium.jar&lt;/a&gt;
&lt;li&gt;&lt;b&gt;Write the code &lt;/b&gt;&lt;br /&gt;
okay let's write the code.. no no no hang on !! before we write the code we need to identify the elements of the flex application.&amp;nbsp; I am using following add-on of Firefox to identify the elements.&lt;br /&gt;
&lt;a href="http://www.o-minds.com/products/flashfirebug"&gt;FlashFirebug &lt;/a&gt;(this is actually a extension of the firebug add-on)&lt;/li&gt;
&lt;pre class="brush:java"&gt;/**
 * @author Gaurang
 */
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.FlexUISelenium;
import com.thoughtworks.selenium.Selenium;

public class TestFlex {
 Selenium selenium;
  private FlexUISelenium flexUITester;
 @Before
 public void setUp() throws Exception {
  selenium = new DefaultSelenium("localhost", 2323, "*chrome", "http://qtp-help.blogspot.com");
  selenium.start();
  while(selenium.isElementPresent("myInput"))
  Thread.sleep(1000);
  selenium.open("/2011/03/flex-example.html");
  flexUITester = new FlexUISelenium(selenium, "selenium_demo");
 }
 
 @Test
 public void test() {
  //Enter text
  flexUITester.type("Gaurang").at("myInput");
  flexUITester.click("myButton");
  assertEquals("Gaurang", flexUITester.readFrom("myText"));
 }
}

&lt;/pre&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-362339532666760356?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1aBA2oc49pYOpUIUCRmJld-_c3w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1aBA2oc49pYOpUIUCRmJld-_c3w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1aBA2oc49pYOpUIUCRmJld-_c3w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1aBA2oc49pYOpUIUCRmJld-_c3w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/_DznPRk05uY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/362339532666760356/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/03/selenium-with-flex.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/362339532666760356?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/362339532666760356?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/_DznPRk05uY/selenium-with-flex.html" title="Selenium with Flex" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/03/selenium-with-flex.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8NQng8fSp7ImA9WhZTE0k.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-212428653687482829</id><published>2011-03-16T16:50:00.007+05:30</published><updated>2011-03-17T13:14:53.675+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-17T13:14:53.675+05:30</app:edited><title>Flex example</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
   id="selenium_demo" width="100%" height="100%"
   codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"&gt;    &lt;param name="movie" value="http://sites.google.com/site/gaurangnshah/selenium_demo.swf" /&gt;&lt;param name="quality" value="high" /&gt;&lt;param name="bgcolor" value="#869ca7" /&gt;&lt;param name="allowScriptAccess" value="sameDomain" /&gt;&lt;embed src="http://sites.google.com/site/gaurangnshah/selenium_demo.swf" quality="high" bgcolor="#869ca7"
    width="100%" height="100%" name="selenium_demo" align="middle"
    play="true"
    loop="false"
    quality="high"
    allowScriptAccess="sameDomain"
    type="application/x-shockwave-flash"
    pluginspage="http://www.adobe.com/go/getflashplayer"&gt;    &lt;/embed&gt;  &lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-212428653687482829?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XiQkd4IxxOnuC0YWo4os_JVY2Io/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XiQkd4IxxOnuC0YWo4os_JVY2Io/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XiQkd4IxxOnuC0YWo4os_JVY2Io/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XiQkd4IxxOnuC0YWo4os_JVY2Io/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/c3eDaMOq6mA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/212428653687482829/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/03/flex-example.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/212428653687482829?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/212428653687482829?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/c3eDaMOq6mA/flex-example.html" title="Flex example" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/03/flex-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEMSX4-cSp7ImA9Wx9bGUw.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-8693712613134752677</id><published>2011-02-08T17:08:00.001+05:30</published><updated>2011-03-01T00:14:48.059+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-01T00:14:48.059+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>selenium test auto suggest</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;There are few editboxes in the application that shows suggestions while you type. In some of the application you need to choose from that suggestions only to filled the edit box else it won't consider as in my application while in other application it is optional, like google search engine. &lt;br /&gt;
&lt;br /&gt;
If you will simple type in the editbox using &lt;i&gt;&lt;b&gt;type&lt;/b&gt;&lt;/i&gt; method it won't give you any suggestion coz it works on keyevent so to see the suggestion you will require to use the &lt;i&gt;&lt;b&gt;keyPressNative&lt;/b&gt;&lt;/i&gt; method. &lt;br /&gt;
&lt;br /&gt;
following code will open the google.com, will type the "selenium handle" in the search editbox and will choose the first option available and will search that.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:java"&gt;public class AutoSuggest {
 Selenium selenium;
 @Before
 public void setUp() throws Exception {
  selenium = new DefaultSelenium("localhost", 2323, "*chrome", "http://www.google.co.in/");
  selenium.start();
 }

 @Test
 public void testUntitled() throws Exception {
  selenium.open("/");
  enterKeyStrokes("selenium handle");
  assertTrue(selenium.isTextPresent("Gaurang Shah"));
 }

 public void enterKeyStrokes(String str) throws InterruptedException {
  char[] strarry = str.toUpperCase().toCharArray();
  selenium.click("q");
  Thread.sleep(1000);
  for(int chars=0; chars&amp;lt;strarry.length; chars++){
   selenium.keyPressNative(""+(int)strarry[chars]);
   Thread.sleep(1000);
  }
  selenium.keyPressNative(String.valueOf(KeyEvent.VK_DOWN));
  selenium.keyPressNative(String.valueOf(KeyEvent.VK_ENTER)); // press enter
  Thread.sleep(2000);
 }
@After
public void tearDown() throws Exception {
 selenium.stop();
}
&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-8693712613134752677?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1npY66Wzv32iP-GwutB90zZ6Yu8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1npY66Wzv32iP-GwutB90zZ6Yu8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1npY66Wzv32iP-GwutB90zZ6Yu8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1npY66Wzv32iP-GwutB90zZ6Yu8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/xUXqln3DQxY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/8693712613134752677/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/02/selenium-test-auto-suggest.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/8693712613134752677?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/8693712613134752677?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/xUXqln3DQxY/selenium-test-auto-suggest.html" title="selenium test auto suggest" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/02/selenium-test-auto-suggest.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0UBQ3kzeyp7ImA9Wx9bFkg.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-7294868151829909819</id><published>2011-01-20T18:55:00.000+05:30</published><updated>2011-02-26T00:10:52.783+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-26T00:10:52.783+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>this.onXhrStateChange.bind is not a function</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Recently I require to work with the proxy injection mode. And as soon as I endup setting selenium for proxy injection mode I got following error. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: red;"&gt;this.onXhrStateChange.bind is not a function on session&amp;nbsp; ad4cf7d3106f4f379a27af514bd1ff5d&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I tried a lot and finally got the solution. Though using this solution I am not getting above error anymore, browser is opening but some of the other command is failing, like waitforpagetoload.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Solution:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;&lt;li&gt;&amp;nbsp;Download the source code of selenium-java-client-driver.Jar file and extract that into one folder&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Open the file DefaultSelenium.Java and replace the "public void open(String url)" function with the following. &lt;br /&gt;
public void open(String url) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; commandProcessor.doCommand("open", new String[] {url,"true"}); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Recompile the file and create new JAR&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Replace the JAR with original JAR, Build the project again and then Run. &lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-7294868151829909819?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fmYKsYn0mGdbmaVj9khitX8Y4s4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fmYKsYn0mGdbmaVj9khitX8Y4s4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fmYKsYn0mGdbmaVj9khitX8Y4s4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fmYKsYn0mGdbmaVj9khitX8Y4s4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/Wb25kbHZzUc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/7294868151829909819/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2011/01/thisonxhrstatechangebind-is-not.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/7294868151829909819?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/7294868151829909819?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/Wb25kbHZzUc/thisonxhrstatechangebind-is-not.html" title="this.onXhrStateChange.bind is not a function" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2011/01/thisonxhrstatechangebind-is-not.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEMSX49eSp7ImA9Wx9bGUw.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-7768325638253771346</id><published>2010-12-30T17:05:00.003+05:30</published><updated>2011-03-01T00:14:48.061+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-01T00:14:48.061+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>Selenium - Handle Upload Dialog</title><content type="html">Download&lt;br /&gt;
&lt;a href="http://www.mediafire.com/?kb69lqoh4mchol9"&gt;Handle_File_Upload.exe&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_dyh51i-x4Hw/TRyL9-jAknI/AAAAAAAAAuQ/vPL85ObwHw0/s1600/selenium_Upload_Dialog.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="296" src="http://2.bp.blogspot.com/_dyh51i-x4Hw/TRyL9-jAknI/AAAAAAAAAuQ/vPL85ObwHw0/s400/selenium_Upload_Dialog.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Following is the Autoit Script to handle upload dialog box.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:vb"&gt;;--------------------------------------------------------------------
;~ File_Upload_FF.au3
;~ Purpose: TO handle the file Upoload dialog
;~ Usage: File_Upload_FF.exe "Dialog Title" "Path of the file"
;~ Create By: Gaurang Shah
;~ Email: shahgomji@gmail.com
;--------------------------------------------------------------------

AutoItSetOption("WinTitleMatchMode","2") ; set the select mode to select using substring

if $CmdLine[0] &amp;lt; 2 then
; Arguments are not enough
msgbox(0,"Error","File_Upload_FF.exe 'Dialog Title' 'Path of the file'")
Exit
EndIf

; wait Until dialog box appears
WinWait($CmdLine[1]) ; match the window with substring
$title = WinGetTitle($CmdLine[1]) ; retrives whole window title
WinActivate($title)

WinWaitActive($title)
ControlSetText($title,"","Edit1",$CmdLine[2])
ControlClick($title,"","&amp;amp;Open")
&lt;/pre&gt;&lt;br /&gt;
You need to download Autoit in order to run this script else you can download the EXE uploaded here. &lt;br /&gt;
&lt;br /&gt;
To know how to call this EXE from JAVA read the following blogpost. &lt;br /&gt;
&lt;a href="http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html"&gt;http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-7768325638253771346?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5kok0lhp-h5_K82Gpxzr1DXNcUU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5kok0lhp-h5_K82Gpxzr1DXNcUU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5kok0lhp-h5_K82Gpxzr1DXNcUU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5kok0lhp-h5_K82Gpxzr1DXNcUU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/hEsBeX_iOnE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/7768325638253771346/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2010/12/selenium-handle-upload-dialog.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/7768325638253771346?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/7768325638253771346?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/hEsBeX_iOnE/selenium-handle-upload-dialog.html" title="Selenium - Handle Upload Dialog" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_dyh51i-x4Hw/TRyL9-jAknI/AAAAAAAAAuQ/vPL85ObwHw0/s72-c/selenium_Upload_Dialog.PNG" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2010/12/selenium-handle-upload-dialog.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEMSX49eip7ImA9Wx9bGUw.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-5524249705665581643</id><published>2010-10-04T12:33:00.008+05:30</published><updated>2011-03-01T00:14:48.062+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-01T00:14:48.062+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>Selenium-Select All Checkboxes</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Few times back i just come across the situation where i require to select all the checkboxes on page. To do that one by one will make code to huge so i think about using loops for that. And here is the solution. &lt;br /&gt;
&lt;br /&gt;
The following code will open the page that has 6 checkboxes and will check them all one by one.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:java; highlight: [22,23,24,25,26,27,28,29]"&gt;import org.testng.annotations.*;
import com.thoughtworks.selenium.*;

public class TestCheckbox {

private Selenium selenium;

@BeforeClass
public void setUp(){

selenium = new DefaultSelenium("localhost", 2323, "*chrome", "http://qtp-help.blogspot.com");
selenium.start();
selenium.open("/");
}

@Test
public void selectAllCheckboxes() throws InterruptedException{
selenium.open("http://qtp-help.blogspot.com/2010/10/selenium-checkbox-example.html");

selenium.waitForPageToLoad("6000");
Thread.sleep(3000);
int totalCheckboxes = selenium.getXpathCount("//input[@type='checkbox']").intValue();
for (int i = 1; i &amp;lt; totalCheckboxes+1; i++) {

if(!selenium.isChecked("//input[@id='checkbox"+i+"']")){
selenium.click("//input[@id='checkbox"+i+"']");

}
}

}

}

&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-5524249705665581643?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Sc_Xrz_ROQYJgTU-DV2dP1xbhVk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Sc_Xrz_ROQYJgTU-DV2dP1xbhVk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Sc_Xrz_ROQYJgTU-DV2dP1xbhVk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Sc_Xrz_ROQYJgTU-DV2dP1xbhVk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/3-Gk7jF7zk0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/5524249705665581643/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2010/10/selenium-select-all-checkboxes.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/5524249705665581643?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/5524249705665581643?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/3-Gk7jF7zk0/selenium-select-all-checkboxes.html" title="Selenium-Select All Checkboxes" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>2</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2010/10/selenium-select-all-checkboxes.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUQGRHo9fyp7ImA9WhdbGUg.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-7208611139695193245</id><published>2010-10-04T11:57:00.010+05:30</published><updated>2011-10-18T21:25:25.467+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-18T21:25:25.467+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>selenium checkbox example</title><content type="html">&lt;input id="checkbox1" name="checkbox1" type="checkbox" value="36" /&gt; First Checbox&lt;br /&gt;
&lt;br /&gt;
&lt;input id="checkbox2" name="checkbox2" type="checkbox" value="36" /&gt; Second Checkbox&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input id="checkbox3" name="checkbox3" type="checkbox" value="36" /&gt; Third Checkbox&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input id="checkbox4" name="checkbox4" type="checkbox" value="36" /&gt; Fourth Checkbox &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input id="checkbox5" name="checkbox5" type="checkbox" value="36" /&gt; Fifth Checkbox&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input id="checkbox6" name="checkbox6" type="checkbox" value="36" /&gt; Sixth Checkbox &lt;br /&gt;
&lt;br /&gt;
&lt;script&gt;
function load() {
var load = window.open('http://www.google.com','google','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=no,status=yes');
}
a=0;
a=a+1;
&lt;/script&gt;&lt;br /&gt;
&lt;input id="Gaurang" name="Dynamic button" onclick="this.value=this.id='Gaurang'+a++" type="button" value="Dynamic button" /&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;a href="javascript:load()"&gt;gaurang00hdhd&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-7208611139695193245?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OxXILAsg8zg-CuoG-qaRU_MCeSY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OxXILAsg8zg-CuoG-qaRU_MCeSY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OxXILAsg8zg-CuoG-qaRU_MCeSY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OxXILAsg8zg-CuoG-qaRU_MCeSY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/GgFCWnU-6tA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/7208611139695193245/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2010/10/selenium-checkbox-example.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/7208611139695193245?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/7208611139695193245?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/GgFCWnU-6tA/selenium-checkbox-example.html" title="selenium checkbox example" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2010/10/selenium-checkbox-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UGQno4fip7ImA9WhdSFkU.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-2212001536766981338</id><published>2010-07-01T17:22:00.012+05:30</published><updated>2011-07-26T17:23:43.436+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-26T17:23:43.436+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Selenium" /><category scheme="http://www.blogger.com/atom/ns#" term="ReportNG" /><category scheme="http://www.blogger.com/atom/ns#" term="TestNG" /><title>TestNG - Take Screenshot of Failed Test Cases.</title><content type="html">In my project I required to take to take the screenshot of the failed test cases. I initially searched for ready made listeners that can do this. Bug when i failed to find any i decided to write down my own.&lt;br /&gt;
&lt;br /&gt;
I also wanted the screenshots to be embedded in ReportNG report. But HTML tags in ReportNG report is by default disabled. You require to set its system property to enable to HTML Tags in report. &lt;br /&gt;
&lt;br /&gt;
The following listener will take the screenshot of the failed testcases and will embed that in your ReportNG report but for that you require to change in your TestNG task in your build.xml. &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight:bold;"&gt;Listener to Take the screenshot of failed testcases&lt;/span&gt;&lt;br /&gt;
&lt;pre class="brush:java"&gt;package test.Lib;

import java.io.File;

import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.TestListenerAdapter;

public class Screenshot extends TestListenerAdapter {

@Override
public void onTestFailure(ITestResult result) {
File file = new File("");

Reporter.setCurrentTestResult(result);
System.out.println(file.getAbsolutePath());
Reporter.log(file.getAbsolutePath());

Reporter.log("screenshot saved at "+file.getAbsolutePath()+"\\reports\\"+result.getName()+".jpg");
Reporter.log("&amp;lt;a href='../"+result.getName()+".jpg' &amp;lt;img src='../"+result.getName()+".jpg' hight='100' width='100'/&amp;gt; &amp;lt;/a&amp;gt;");
BaseClass.selenium.captureScreenshot(file.getAbsolutePath()+"\\reports\\"+result.getName()+".jpg");
Reporter.setCurrentTestResult(null);
}


@Override
public void onTestSkipped(ITestResult result) {
// will be called after test will be skipped
}

@Override
public void onTestSuccess(ITestResult result) {
// will be called after test will pass 
}

}

&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight:bold;"&gt;BaseClass:&lt;/span&gt; BaseClass is the class where my setup(@BeforeClass) and teardown(@AfterClass) method is declared. I have taken selenium object is static so i can access it directly by its classname. &lt;br /&gt;
&lt;br /&gt;
To use this listener you need to mention that in your Testng.xml file as follows. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;suite name="TestNG Take Screenshot of failed Test cases"&amp;gt;
&amp;lt;listeners&amp;gt;
&amp;lt;listener class-name="Screenshot" /&amp;gt; 
&amp;lt;/listeners&amp;gt;
&amp;lt;test verbose="6" name="Summery and Submit Page Page"&amp;gt;
&amp;lt;classes&amp;gt;
&amp;lt;class name=test.Lib.testScreenshot" /&amp;gt;
&amp;lt;/classes&amp;gt;
&amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight:bold;"&gt;Changes Require in TestNG task to enable HTML tags in ReportNG report. &lt;/span&gt;&lt;br /&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;project name="ScreenShotFailedTestcases" basedir="."&amp;gt;
&amp;lt;target name="TestNG" depends="compile"&amp;gt;
&amp;lt;taskdef resource="testngtasks" classpathref="lib.classpath"/&amp;gt;
&amp;lt;testng outputDir="${report.dir}" 
haltonfailure="false"
useDefaultListeners="false"
listeners="org.uncommons.reportng.HTMLReporter"
classpathref="lib.classpath"&amp;gt;
&amp;lt;!-- &amp;lt;classfileset dir="${classes.dir}" includes="**/*.class" /&amp;gt; --&amp;gt;
&amp;lt;xmlfileset dir="${basedir}" includes="testng.xml"/&amp;gt;  
&amp;lt;sysproperty key="org.uncommons.reportng.escape-output" value="false"/&amp;gt;
&amp;lt;/testng&amp;gt; 
&amp;lt;/target&amp;gt;
&amp;lt;/project&amp;gt;
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-2212001536766981338?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hYE-GkfA2gVykmAiwlb34xSfU7Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hYE-GkfA2gVykmAiwlb34xSfU7Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hYE-GkfA2gVykmAiwlb34xSfU7Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hYE-GkfA2gVykmAiwlb34xSfU7Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/VOFRaP80qIU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/2212001536766981338/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2010/07/testng-take-screenshot-of-failed-test.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2212001536766981338?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2212001536766981338?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/VOFRaP80qIU/testng-take-screenshot-of-failed-test.html" title="TestNG - Take Screenshot of Failed Test Cases." /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2010/07/testng-take-screenshot-of-failed-test.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0cDQns7fCp7ImA9WhdSFkU.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-2613380324650117262</id><published>2010-06-01T19:57:00.007+05:30</published><updated>2011-07-26T17:21:13.504+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-26T17:21:13.504+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ANT" /><category scheme="http://www.blogger.com/atom/ns#" term="JUnit" /><title>ANT Exec task - Open New Command Prompt</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-weight: bold;"&gt;How to Open New Command Prompt Using ANT task. ??&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Currently we were working on ANT script to run the Selenium Test. And we think it would be nice if ANT script also starts the web server before executing test cases. &lt;br /&gt;
&lt;br /&gt;
To start the web application we require to fire a command from command prompt. we used the Exec task task and it was working fine but problem was it was logging on the same command prompt from which we have run ANT task. We require to open the new command prompt for that.&lt;br /&gt;
&lt;br /&gt;
We tried the cmd /k option but it was not working. Finally we got the solution and it is as below.&lt;br /&gt;
&lt;pre class="brush:xml"&gt;&lt;property name="appDir" value="C:\SVN"&gt;
&lt;target name="run-app"&gt;
&lt;echo&gt; Starting application &lt;/echo&gt;
&lt;exec dir="${appDir}" executable="cmd"&gt; 
&lt;arg line="/K start java -jar application.jar"&gt; 
&lt;/arg&gt;
&lt;/exec&gt;
&lt;/target&gt;&lt;/property&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
In the script &lt;b&gt;appDir&lt;/b&gt; is the Directory path where your server resides. &lt;br /&gt;
and &lt;b&gt;grails run-app&lt;/b&gt; is the command we need to run the command prompt to launch the web application.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-2613380324650117262?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vnVL-FKFZmrbNkWEnZNAxShQ32Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vnVL-FKFZmrbNkWEnZNAxShQ32Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vnVL-FKFZmrbNkWEnZNAxShQ32Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vnVL-FKFZmrbNkWEnZNAxShQ32Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/aNmOk6zetTw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/2613380324650117262/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2010/06/ant-exec-task-open-new-command-prompt.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2613380324650117262?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/2613380324650117262?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/aNmOk6zetTw/ant-exec-task-open-new-command-prompt.html" title="ANT Exec task - Open New Command Prompt" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2010/06/ant-exec-task-open-new-command-prompt.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkEAQn84cCp7ImA9WxBQEkw.&quot;"><id>tag:blogger.com,1999:blog-1282146880741978115.post-3316307509984286636</id><published>2010-01-11T17:11:00.003+05:30</published><updated>2010-01-11T18:27:23.138+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-11T18:27:23.138+05:30</app:edited><title>Top 3 movies of 2009</title><content type="html">Many Hindi and English movies released in this year.. but following are 3 I like most.&lt;br /&gt;&lt;br /&gt;1. 3 idiots &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://upload.wikimedia.org/wikipedia/en/thumb/d/dc/Threeidiots2.jpg/200px-Threeidiots2.jpg"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 200px; height: 290px;" src="http://upload.wikimedia.org/wikipedia/en/thumb/d/dc/Threeidiots2.jpg/200px-Threeidiots2.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;With no doubt this is the best movie for me of year 2009. After so so long time bollywood finally comes with the movie that I wants to see over and over ( after sholey and Dilwane Dulhaniya Le jayenge). Though I like the novel much more than movie, I think it's better for the movie that they have changed few things.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Avatar &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://upload.wikimedia.org/wikipedia/en/thumb/b/b0/Avatar-Teaser-Poster.jpg/200px-Avatar-Teaser-Poster.jpg"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 200px; height: 297px;" src="http://upload.wikimedia.org/wikipedia/en/thumb/b/b0/Avatar-Teaser-Poster.jpg/200px-Avatar-Teaser-Poster.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;After terminator and titanic, James Cameron did it again. It's whole new experience to watch AVATAR that you can't describe in words. You just need to watch that.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. Hangover &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://upload.wikimedia.org/wikipedia/en/b/b9/Hangoverposter09.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 308px;" src="http://upload.wikimedia.org/wikipedia/en/b/b9/Hangoverposter09.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The best comedy movie of the year according to me. The story telling, Where everything reveals step by step is superb.  you just don't want to miss a scene of the movie. Amazing direction and timing of comedy.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1282146880741978115-3316307509984286636?l=qtp-help.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_RioXLY7zqKfxInAy5mLywJSAj0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_RioXLY7zqKfxInAy5mLywJSAj0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_RioXLY7zqKfxInAy5mLywJSAj0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_RioXLY7zqKfxInAy5mLywJSAj0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GaurangShahAboutAutomationWithQtp/~4/e8f_Gi6BYmY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://qtp-help.blogspot.com/feeds/3316307509984286636/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://qtp-help.blogspot.com/2010/01/top-3-movies-of-2009.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/3316307509984286636?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1282146880741978115/posts/default/3316307509984286636?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GaurangShahAboutAutomationWithQtp/~3/e8f_Gi6BYmY/top-3-movies-of-2009.html" title="Top 3 movies of 2009" /><author><name>Gaurang Shah</name><uri>http://www.blogger.com/profile/08771276997741729373</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_dyh51i-x4Hw/SoEiniFxAAI/AAAAAAAAAJ8/XUG96TinPfk/S220/DSCI0978_edited-1.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://qtp-help.blogspot.com/2010/01/top-3-movies-of-2009.html</feedburner:origLink></entry></feed>

