Cross browser testing using TestNG and Selenium WebDriver

This is the app age in IT sector. Every day we get information about the launch of the new app. It is good because ultimately app makes our life easier. An app is not only limited to booking flight ticket but also, it is used to order online food, groceries, medical consultancy, teaching, and learning, for any kind of online shopping and much more. Even apps help you control your home automation system. Due to the wider usability of apps, it is categorized as a web app, mobile app, and desktop app. Every user has their favorite browser among Chrome, Safari, Internet Explorer, Opera, Mozilla Firefox, etc. So, we can draw a conclusion that users are distributed over different browsers. Therefore, cross browser testing is mandatory to assure that the product is working as expected for all kinds of users.

Before we dig more inside the cross-browser testing, I’d like to suggest you 3 minutes reading articles on interview questions. Click on the link below to read.

What is cross browser testing?

Cross-browser testing is the testing of the web applications in different web browsers to making sure that the application is compatible and working as expected.

Why do we need to achieve cross-browser testing?

There are many reasons to answer this question. Firstly, look at the image below.

Cross browser testing inviul

Above image is the footer part of our lovely blog – Left portion is the screenshot of Chrome browser, whereas, right portion is the screenshot of Internet Explorer. Zig jag line is the expectation and it is present in the Google Chrome browser, whereas, it is not present in the Internet Explorer, hence, cross browser testing is performed to overcome such gaps.

Here are the points to perform cross-browser testing:

  • Cross-browser testing is performed to check the compatibility
  • It motivates JavaScript validation
  • Page alignment can be checked
  • Location and Image orientation validation
  • CSS validation in different browsers
  • HTML 5 compatibility check
  • Font size validation in different browsers

How to implement Cross browser testing in Selenium?

We got an overview of the cross-browser testing. Now it’s time to know its implementation in your automation project. You need to satisfy some pre-requisites before you implement with the programming language.


  • Chromedriver
  • Microsoftdriver
  • Geckodriver
  • Drivers for any other browser

Below code is the implementation of the cross-browser testing in Selenium. We simply define browser name in tesng.xml file within <parameter></>. We further inject browser name to the method written inside @BeforeMethod annotation. Further, it switches between the browser name and performs the validation.



Console output

Cross browser testing console

That’s all about cross-browser testing in Selenium using TestNG. You can post your queries in the comment form below.

Leave a Reply