4 Best Practices To Be Employed For Cross Browser Testing In Selenium


Subscribe to our Newsletter

Testers try to perform a test on all possible browsers and their versions while verifying the site functionality. This test is usually performed by using Selenium as it is equipped for facilitating Cross Browser testing. This article dives by understanding how to perform Cross Browser testing using Selenium.

What is Cross Browser testing in Selenium?

Cross Browser testing a website in multiple browsers like internet explorer, Chrome, Firefox for checking its effectiveness. Cross Browser compatibility is the strength of the website for a web application to function across various browsers and operating systems.

Nevertheless, manually testing a website across multiple browsers is particularly tiresome. Considering a situation in which hundred test cases are to be run manually. If we imagine that the same tests have to be run on five different browsers, the time required will become exponentially higher. Nevertheless, if these tests are automated using Selenium, they could be run simultaneously and far less.

What is the importance of Cross Browser testing?

Browser vendors follow open web standards, but they do have their interpretations of it. Since they render HTML, CSS, and find JavaScript in different ways for debugging a website, source code isn’t enough for ensuring that the site will look and behave as expected on different browsers or different versions of a single browser.

So it depends on web developers for extracting browser differences. Cross Browser compatibility testing helps in it by pinpointing browser-specific compatibility errors so they can debug them easily. It helps ensure that the website does not separate a significant part of its target audience simply because the website doesn’t work on their browser OS.

How can Cross Browser testing be performed using Selenium?

As mentioned, Selenium is among the most popular automation testing tools for different functionalities. Cross browser testing is one such feature that Selenium supports that could be performed by following the steps below:

Step 1:

Test cases could be automated using internet explorer, Firefox, Chrome, Safari browsers with Selenium WebDriver.

Step 2:

Executing test cases by different browsers in the same machine simultaneously, a TestNG framework could be integrated with Selenium WebDriver.

Step 3:

Writing the test cases.

package test;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.edge.EdgeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

public class CrossBrowserTestingScript {

WebDriver driver;


* This function will execute before each Test tag in testng.xml

* @param browser

* @throws Exception




public void setup(String browser) throws Exception{

//Check if parameter passed from TestNG is ‘firefox’


//create firefox instance

System.setProperty(“Path of your gecko driver”);

driver = new FirefoxDriver();


//Check if parameter passed as ‘chrome’

else if(browser.equalsIgnoreCase(“chrome”)){

//set path to chromedriver.exe

System.setProperty(“Path of your chrome driver”);

driver = new ChromeDriver();


else if(browser.equalsIgnoreCase(“Edge”)){

//set path to Edge.exe

System.setProperty(“Path of edge driver”);

driver = new EdgeDriver();



//If no browser is passed throw exception

throw new Exception(“Incorrect Browser”);


driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);



public void testParameterWithXML() throws InterruptedException{


WebElement Login = driver.findElement(By.linkText(“Sign in”));

//Hit Sign-in button



WebElement userName = driver.findElement(By.id(“user_email_login”));

//Fill user name

userName.sendKeys(“your email id”);


//Find password’

WebElement password = driver.findElement(By.id(“user_password”));

//Fill password

password.sendKeys(“your password”);


WebElement Signin= driver.findElement(By.(id(“user_submit”));

//Hit search button





The above code seeks to use three separate web browsers to navigate the BrowserStack website by configuring the device properties of each window. Let’s write the file testng.xml to run the test cases.

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE suite SYSTEM “<a href=”http://testng.org/testng-1.0.dtd”>http://testng.org/testng-1.0.dtd</a>”>

<suite name=”TestSuite” thread-count=”2″ parallel=”tests” >

<test name=”ChromeTest”>

<parameter name=”browser” value=”Chrome”/>


<class name=”test.CrossBrowserTestingScript”>




<test name=”FirefoxTest”>

<parameter name=”browser” value=”Firefox” />


<class name=”test.CrossBrowserTestingScript”>




<test name=”EdgeTest”>

<parameter name=”browser” value=”Edge” />


<class name=”test.CrossBrowserTestingScript”>





In this XML file, the code sets various classes for instantiating browsers to run the on-the-site test cases. That’s how it works.

Best practices for Cross Browser Testing in Selenium

The best practices that should be followed during multi-browser testing of Selenium should be followed:

Choose libraries and frameworks cautiously

Web applications need frameworks and libraries to be tested. Before developing the system, bear in mind that the new CSS frames could build the most interactive and vibrant user interface but might not be consistent with any browser. A special browser renders each browser. Read browser guides to decide if they accept certain libraries and frameworks before using the new CSS or JS libraries or frameworks.

Use proper JavaScript libraries and task runners

The use of the right JavaScript tools complying with website needs and providing compliant browser support is critical in creating a Web App. Many choices could be chosen from among Mission Runners. Gulp and Grunt distinguish themselves since the specifications can be automated. They also increase overall application efficiency by ensuring that code quality is improved after building, linting, mining, and other functions.

Carefully identify and analyze the Browser-OS configuration

QAs must decide on which browsers and frameworks to test a site. Each browser has many versions, and certain browsers are also regularly updated – at least once a month. It means that Cross Browser tests are needed with Selenium to check which browser, browser variants, and OS. Prioritize the variations expected to be used by the biggest segments of the target demographic.

Optimize Internet Explorer

Internet Explorer does not support specialized frameworks and CSS forms. While an area is the absolute peak of aesthetic appeal, many architectural features are likely to be blurred when accessed by IE. Build a new IE style sheet and apply a hack to the doctype to correct this.


Performing Cross Browser testing Selenium is essential as it ensures that the web app is Cross Browser compatible and provides a robust user experience across the board. Cross Browser tests should be run on a real device cloud forgetting completely accurate results as always.

Contact Us

Hire vetted developers & testers with Appsierra to build & scale your software products

Trusted by 100x of startups and enterprise companies like

Read More

Subscribe to Our Newsletter