Runing test script in multiple browsers using WebDriver

we can run test script in different browsers using web driver. Write one test script and configure in testng xml to run that test case in IE, firefox chrome.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.Assert;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class WebDriverDemo {

 private static WebDriver driver = null;

 @Parameters( {"BROWSER"})
 public  void testread(String BROWSER)throws Exception{

  System.out.println("Browser: " + BROWSER);

  if (BROWSER.equals("FF")) {
   System.out.println("FF is selected");
   driver = new FirefoxDriver();
  } else if (BROWSER.equals("IE")) {
   System.out.println("IE is selected");
   driver = new InternetExplorerDriver();
  } else if (BROWSER.equals("HU")) {
   System.out.println("HU is selected");
   driver = new HtmlUnitDriver();
  } else if (BROWSER.equals("CH")){
   System.out.println("Google chrome is selected");
   driver = new ChromeDriver();
  WebElement search= driver.findElement("p"));
  search.sendKeys("automation blog by niraj");
  Assert.assertTrue(driver.getPageSource().contains(""),"Failed in "+ BROWSER);


In the above sample program BROWSER is a variable which value would be passed from TestNG.xml and TestNG.xml will run the test multiple time each time BROWSER value would be set with different browser name and test will check the BROWSER value and decide which browser test will run.


<?xml version="1.0" encoding="UTF-8"?>
<suite name="webDriver">
 <test name="WebDriverDemo Witn FF" preserve-order="true">
  <parameter name="BROWSER" value="FF" />
   <class name="com.web.WebDriverDemo" />
  <test name="WebDriverDemo with IE" preserve-order="ture">
  <parameter name="BROWSER" value="IE"></parameter>
   <class name="com.web.WebDriverDemo"></class>
 <test name="WebDriverDemo with HTML unit" preserve-order="true">
  <parameter name="BROWSER" value="HU"></parameter>
   <class name="com.web.WebDriverDemo"></class>
 <test name="WebDriverDemo with chrome" preserve-order="true">
  <parameter name="BROWSER" value="CH"></parameter>
   <class name="com.web.WebDriverDemo"></class>


  1. Excellent post!!! Selenium automation testing tool makes your software validation process lot simpler. Keep on updating your blog with such awesome information. Selenium Course in Chennai

  2. This site provides good information about mobile app testing. If anyone wants to know the basics of mobile app testing then this is the right blog for them. mobile application testing training in Chennai | mobile application testing training

  3. GSSSB 2480 Revenue Talati Bharti Recruitment 2016

    Thanks for the marvelous posting! I certainly enjoyed reading it, you are a great author.....

  4. Assam 2564 Police Constable Recruitment 2016 Apply Online

    The information mentioned in the blog are several of the very best available................

  5. I agree with your post. Selenium is most used automation tool to test web application and browser. This automation tool offers precise and complete information about a software application or environment. Selenium Training in Chennai

  6. Shree Ram Techno Solutions Provides CCTV Camera, Security Camera, Wireless Security, Attendance System, Access Control System, DVR, NVR, Spy Camera, Fire Alarm, Security Alarm, PCI, IP Network Camera, Dome Camera, IR Camera, CCTV, Camera Price, HIKVISION, SCATI, Time Machine

    CCTV CAmera in jaipur at Rajasthan
    Home security system in jaipur
    Wireless Home Security System in jaipur
    Realtime attendance machine in jaipur
    cctv camera dealer in jaipur
    Hikvision DVR in jaipur at Rajasthan
    security system solutions in jaipur

  7. It is nice post and I found some interesting information on this blog, keep it up. Thanks for sharing.

    Best Bridal Makeup Artist in Chennai

  8. I am always searching online for articles that can help me. There is obviously a lot to know about this.

  9. nice blog
    Great Information.
    Makeup Institute
    The need to feel beautiful and younger is increasing and latest trends are getting introduced every now and then.

  10. nice blog
    great information.
    VLCC Institute Advance Nail Art and Nail Extension Course provides finest level of learning in Nail art techniques like 3D Art,
    Nail Piercing with Jwellery, Upper form with inbuilt design, Transfer foil designs and many more.