Input your search keywords and press Enter.

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 – inviul.com. 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.

Pre-requisites

  • 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.

CrossBrowserTestingDemo.class

Testng.xml

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.

Avinash Mishra is the author of Inviul blog. He is a software engineer and blogger by choice. He loves to write blogs, and apart from blogging, he is interested in documentary film making, listening to music, traveling around the world and philanthropic activities.

Leave a Reply

Your email address will not be published. Required fields are marked *