Browser Compatibility Testing using Selenium and TestNG

Cross Browser Testing : Is  to check that your web application works as expected in different browsers.If we are using Selenium WebDriver, we can automate test cases using Internet Explorer, FireFox, Chrome, Safari browsers.To execute test cases with different browsers in the same machine at same time we can integrate TestNG with Selenium WebDriver.

Lets create a class Testng_BC.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Reporter;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Testng_BC
public WebDriver fd;
public void browserTest(String str) throws Exception

fd=new FirefoxDriver();


//Following code is to set the ie driver with webdriver property.You need IE Driver //server. download from here.
fd=new InternetExplorerDriver();

else {
Reporter.log(“test failed”);


Now create testng.xml file and paste the below code

<suite name=”Suite>

<test name=”FirefoxTest>
  <parameter name=”browser value=”firefox />
  <class name=”Testng_BC />
<test name=”IETest>
  <parameter name=”browser value=”ie />
  <class name=”Testng_BC />
To execute a testcase in IE browser we have to use IE Driver server.And you have change few settings.
1.Open IE
2.Go to Tools -> Internet Options -> Security
3.Set all zones to the same protected mode, enabled or disabled should not matter.
Finally, set Zoom level to 100% by right clicking on the gear located at the top right corner and enabling the status-bar. Default zoom level is now displayed at the lower right.
Why are we passing parameters ??
To run the Testng_BC class in multiple browsers, we have to pass the parameters from xml.From parameters in testing.xml we can pass browser name and in test case we can create WebDriver reference accordingly.
Now run the testng.xml file, it should execute ‘browserTest’ in Firefox and  IE Browsers.If you refresh the project and look into test-output folder, a html report (index.html) has been generated.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s