Cross Browser Testing using Selenium WebDriver

Cross Browser Testing using Selenium WebDriver to run Test Scripts in different browsers like Google Chrome,Firefox ,Internet Explorer etc at a same time then we have to use TestNG Framework for Automating Cross Browser Testing using Selenium WebDriver.

What is Cross Browser Testing?

Cross Browser Testing means testing the application under test(AUT) with different browsers in order to verify all functionalities are working same in all browsers.

Problems if not done Cross Browser Testing

1.Main defect is Design issue.
2.Some functionalities not supports javascript because of browser
3.Some functionalities will not work in some browsers because of configurations.
4.Some time facing issues while uploading/Downloading file formats.
5.Faacing the problems with additional plugins like displaying grid details in applications.
6.Some functionalities will not work changing the compatibility mode in browsers.

ALSO READ  Selenium Introduction

In order to over come above some problems we have to perform Cross Browser Testing for applications under test(AUT).

Also Read Run Selenium Script using runnable JAR


2.Different browsers drivers(IE Driver,Chrome Driver etc).
3.Test Script class for test cases.
4.Declaring the browsers in a class.
5.@Parameters annotation which Describes how to pass parameters to a @Test method,where we are writing our Test Cases  i.e Test Scripts.

Example for Cross Browser Testing

Prepare textng.xml file to set up parameters for different browsers,follow same code as below.

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "">
<suite name="Cross Browser Testing" preserve-order="true" verbose="2"
<parameter name="Weburl" value=""></parameter>
<test name="Internet Explorer">
<parameter name="WebBrowser" value="ie"></parameter>
<class name="" />
<test name="Google Chrome">
<parameter name="WebBrowser" value="chrome"></parameter>
<class name="" />
<test name="Firefox">
<parameter name="WebBrowser" value="firefox"></parameter>
<class name="" />

Now create two classes one class is for driver initialization and Browser setting and second clas is for Test Scripts under @Test annotaition’s,follow below classesCreate class to initialize the driver and browsers set up as below.

ALSO READ  TestNG - Cannot find class in classpath Error

Also Read Send Extent Reports in Email with Screenshots

package gmail.automation;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

public class SelDriver {
public static WebDriver driver;
static String baseUrl;

public void setup(String WebBrowser){
//Adding verfication point using IF Condition
driver = new FirefoxDriver(); 
}else if(WebBrowser.equalsIgnoreCase("ie"))
//For ie browser we have to use System.SetProperty 
System.setProperty("", "F:\Java_Applications\Zip Files\IEDriverServer.exe"); 
driver = new InternetExplorerDriver(); 
}else if(WebBrowser.equalsIgnoreCase("chrome")){ 
//For Google chrome browser we have to use System.setProperty and Chrome Driver 
System.setProperty("", "F:\Java_Applications\Zip Files\chromedriver.exe"); 
driver = new ChromeDriver(); 
//Maximize the windows of all browsers

public void tearDown() {
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Now i am using Wikishown class and using inheritance wit the help of extends keyword as below.

ALSO READ  Run Selenium Webdriver Scripts using Command Line

Also Read Run Selenium Webdriver Scripts using Command Line


import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Cross extends SelDriver {

public void testMethod(String Weburl){

//Navigate to URL and Weburl is taking from testng.xml file
//wait until page loads
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.liknText("Manual Testing")).click();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);

Above in two classes i have used @Parameters annotation to call parameter name from xml file.Now run xml file as run as — TestNG Suite then it will run all @Test methods in a class and displays test execution results in Console as well as Test NG icon.

Rajesh K