
- Selenium - Home
- Selenium - Overview
- Selenium - Components
- Selenium - Automation Testing
- Selenium - Environment Setup
- Selenium - Remote Control
- Selenium - IDE Introduction
- Selenium - Features
- Selenium - Limitations
- Selenium - Installation
- Selenium - Creating Tests
- Selenium - Creating Script
- Selenium - Control Flow
- Selenium - Store Variables
- Selenium - Alerts & Popups
- Selenium - Selenese Commands
- Selenium - Actions Commands
- Selenium - Accessors Commands
- Selenium - Assertions Commands
- Selenium - Assert/Verify Methods
- Selenium - Locating Strategies
- Selenium - Script Debugging
- Selenium - Verification Points
- Selenium - Pattern Matching
- Selenium - JSON Data File
- Selenium - Browser Execution
- Selenium - User Extensions
- Selenium - Code Export
- Selenium - Emitting Code
- Selenium - JavaScript Functions
- Selenium - Plugins
- Selenium WebDriver Tutorial
- Selenium - Introduction
- Selenium WebDriver vs RC
- Selenium - Installation
- Selenium - First Test Script
- Selenium - Driver Sessions
- Selenium - Browser Options
- Selenium - Chrome Options
- Selenium - Edge Options
- Selenium - Firefox Options
- Selenium - Safari Options
- Selenium - Double Click
- Selenium - Right Click
- HTML Report in Python
- Handling Edit Boxes
- Selenium - Single Elements
- Selenium - Multiple Elements
- Selenium Web Elements
- Selenium - File Upload
- Selenium - Locator Strategies
- Selenium - Relative Locators
- Selenium - Finders
- Selenium - Find All Links
- Selenium - User Interactions
- Selenium - WebElement Commands
- Selenium - Browser Interactions
- Selenium - Browser Commands
- Selenium - Browser Navigation
- Selenium - Alerts & Popups
- Selenium - Handling Forms
- Selenium - Windows and Tabs
- Selenium - Handling Links
- Selenium - Input Boxes
- Selenium - Radio Button
- Selenium - Checkboxes
- Selenium - Dropdown Box
- Selenium - Handling IFrames
- Selenium - Handling Cookies
- Selenium - Date Time Picker
- Selenium - Dynamic Web Tables
- Selenium - Actions Class
- Selenium - Action Class
- Selenium - Keyboard Events
- Selenium - Key Up/Down
- Selenium - Copy and Paste
- Selenium - Handle Special Keys
- Selenium - Mouse Events
- Selenium - Drag and Drop
- Selenium - Pen Events
- Selenium - Scroll Operations
- Selenium - Waiting Strategies
- Selenium - Explicit/Implicit Wait
- Selenium - Support Features
- Selenium - Multi Select
- Selenium - Wait Support
- Selenium - Select Support
- Selenium - Color Support
- Selenium - ThreadGuard
- Selenium - Errors & Logging
- Selenium - Exception Handling
- Selenium - Miscellaneous
- Selenium - Handling Ajax Calls
- Selenium - JSON Data File
- Selenium - CSV Data File
- Selenium - Excel Data File
- Selenium - Cross Browser Testing
- Selenium - Multi Browser Testing
- Selenium - Multi Windows Testing
- Selenium - JavaScript Executor
- Selenium - Headless Execution
- Selenium - Capture Screenshots
- Selenium - Capture Videos
- Selenium - Page Object Model
- Selenium - Page Factory
- Selenium - Record & Playback
- Selenium - Frameworks
- Selenium - Browsing Context
- Selenium - DevTools
- Selenium Grid Tutorial
- Selenium - Overview
- Selenium - Architecture
- Selenium - Components
- Selenium - Configuration
- Selenium - Create Test Script
- Selenium - Test Execution
- Selenium - Endpoints
- Selenium - Customizing a Node
- Selenium Reporting Tools
- Selenium - Reporting Tools
- Selenium - TestNG
- Selenium - JUnit
- Selenium - Allure
- Selenium & other Technologies
- Selenium - Java Tutorial
- Selenium - Python Tutorial
- Selenium - C# Tutorial
- Selenium - Javascript Tutorial
- Selenium - Kotlin Tutorial
- Selenium - Ruby Tutorial
- Selenium - Maven & Jenkins
- Selenium - Database Testing
- Selenium - LogExpert Logging
- Selenium - Log4j Logging
- Selenium - Robot Framework
- Selenium - AutoIT
- Selenium - Flash Testing
- Selenium - Apache Ant
- Selenium - Github Tutorial
- Selenium - SoapUI
- Selenium - Cucumber
- Selenium - IntelliJ
- Selenium - XPath
- Selenium Miscellaneous Concepts
- Selenium - IE Driver
- Selenium - Automation Frameworks
- Selenium - Keyword Driven Framework
- Selenium - Data Driven Framework
- Selenium - Hybrid Driven Framework
- Selenium - SSL Certificate Error
- Selenium - Alternatives
Selenium Webdriver - Cross Browser Testing
The test case developed in Selenium Webdriver should be able to run in multiple browsers like Chrome, Firefox, Safari, Edge, and so on with minor updates to the test case. This helps to check if the application under test is working as per the requirements in all the browsers.
Why is Cross Browser Testing Beneficial?
Often on working on any applications for example, e-commerce or on travel reservations, and so on, we observe that while doing the payment, or adding products to cart, the applications are taking too much time for page load on a specific browser.
As a user, we promptly infer that there may be an error or an ongoing issue in that application, and we move towards a different company website having the similar products and functionalities.
The web application and apps built on JavaScript, HTML, and CSS render dissimilarly, in spite of the fact browser vendors are based on the Open Web Standards. This results in representation of applications different in different browsers. The source code debugging of any application does not give any insight on how it will be represented in different browsers.
Thus cross browser testing is beneficial to detect compatibility issues of any application in any browser earlier so that it can be used widely for all kinds of users rather than any targeted user group. Also, while doing automated cross browser testing, we may end up creating a test suite with parallel execution, which will help us to scale up the test.
The cross browser testing ensures that which has been application built can be used smoothly with a nice user participation irrespective of any browsers or operating systems.
Example
Let us take an example of the below page, where we have the New User button on the Welcome Page.

On clicking the New User button, we will be navigating to the Registration page, having the Welcome, Register text as shown in the below image.

For the above example, we would do a cross browser testing of the above functionalities in Chrome, and Edge browsers. In order to run the tests simultaneously in two browsers in the same local system, we would take the help of TestNg unit test automation framework. All the test cases would be under the same CrossBrw package. We would run the test in both the browsers by passing the values using the @Parameters tag in the test class BrowserTest.java and specified the parameter = browser and its value = Chrome, and value = Edge in the testng.xml file.

Code Implementation on test class BrowserTest.java.
package CrossBrw; 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.testng.annotations.*; import java.util.concurrent.TimeUnit; public class BrowserTest { WebDriver driver; @BeforeTest @Parameters("browser") public void setup(String browser) throws Exception{ // Initiate browser driver as per browser value if (browser.equalsIgnoreCase("Chrome")) { driver = new ChromeDriver(); System.out.println("Browser opened in Chrome"); } else if (browser.equalsIgnoreCase("Edge")) { driver = new EdgeDriver(); System.out.println("Browser opened in Edge"); } // adding implicit wait of 12 secs driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Opening the webpage driver.get("https://www.tutorialspoint.com/selenium/practice/login.php"); } @Test(priority = 1) public void verifyWelcomePageHeading() { WebElement t = driver.findElement(By.xpath("//*[@id='signInForm']/h1")); System.out.println("Page heading in Welcome Page: " + t.getText()); } @Test(priority = 2) public void moveToRegisterPage() { WebElement btn = driver.findElement(By.xpath("//*[@id='signInForm']/div[3]/a")); btn.click(); } @Test(priority = 3) public void verifyRegisterPageHeading() { WebElement t = driver.findElement(By.xpath("//*[@id='signupForm']/h1")); System.out.println("Page heading in Register Page: " + t.getText()); } @AfterTest public void teardown() { // quitting browser driver.quit(); } }
Configurations in testng.xml.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="All Test Suite" thread-count="5" parallel="tests"> <test thread-count="5" name="ChromeTest"> <parameter name="browser" value="Chrome"></parameter> <classes> <class name="CrossBrw.BrowserTest"/> </classes> </test> <!-- Test --> <test thread-count="5" name="EdgeTest"> <parameter name="browser" value="Edge"></parameter> <classes> <class name="CrossBrw.BrowserTest"/> </classes> </test> </suite>
Dependencies in pom.xml.
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>SeleniumJava</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>16</maven.compiler.source> <maven.compiler.target>16</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.11.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.testng/testng --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.9.0</version> <scope>test</scope> </dependency> </dependencies> </project>
We would need to run the test from the testng.xml file, by right clicking on it, and selecting the option Run testng.xml.
Output
Browser opened in Chrome Browser opened in Edge Page heading in Welcome Page: Welcome, Login In Page heading in Register Page: Welcome,Register Page heading in Welcome Page: Welcome, Login In Page heading in Register Page: Welcome,Register =============================================== All Test Suite Total tests run: 6, Passes: 6, Failures: 0, Skips: 0 =============================================== Process finished with exit code 0

In the above example, we had first passed the parameter browser and its values Chrome, and Edge within the testng.xml files. Within the test class BrowserTest.java, we had executed the test methods - verifyWelcomePageHeading(), moveToRegisterPage(), and verifyRegisterPageHeading() once in Chrome, and then in Edge.
We had taken help of the TestNG test framework along with Selenium Webdriver, to implement the cross browser testing and retrieved the page headers with the messages two times(once in Chrome, and then Edge) in the console - Page heading in Welcome Page: Welcome, Login In, Page heading in Register Page: Welcome,Register, Page heading in Welcome Page: Welcome, Login In, and Page heading in Register Page: Welcome,Register. We had also obtained the messages for the test method setup() having the @BeforeTest annotation in the console - Browser opened in Chrome, and Browser opened in Edge.
The result in the console shows Total tests run: 6, as there are three methods with @Test annotations - verifyWelcomePageHeading(), moveToRegisterPage(), and verifyRegisterPageHeading() were executed twice(for Chrome, and Edge).
Finally, the message Passes: 6, and Process finished with exit code 0 was received, signifying successful execution of the code.
This concludes our comprehensive take on the tutorial on Selenium Webdriver - Cross Browser Testing. Weve started with describing cross browser testing, and why cross browser testing is beneficial, and an example illustrating how to use a cross browser along with Selenium and TestNG. This equips you with in-depth knowledge of the cross browser testing. It is wise to keep practicing what youve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.