top of page
kalesheetal25

Cross Browser Testing Using Testng  & Selenium

What is Cross Browser Testing:

Cross Browser Testing is a type of testing where the tester is assured if the website or the web application looks and works well in with different browsers on many different platforms and versions.

With the help of cross browser testing we can test out applications in different browsers and making sure that it works consistently and as in intended without any dependencies or compromise in quality. This is application for both web and mobile.

Why we should use cross browser testing :

  1. User can open website on any browser or device which gives positive impact on users. So it ensures compatibility across various browsers.

  2. It also helps to meet quality expectation of client.

  3. Security Assurance is one of the important factor of to use cross browser testing. It ensures that your application getting high security standard on all platform which helps to ensure your client's data is safe .  

With the help of TestNG and selenium we can run same test on different browsers and we can verify output of that test scenarios on a different browser. With the help of Cross browser testing , we can ensure that the site is rendered the same on every browser. Cross Browser Testing in selenium can be done by parameterizing the browser variable. Before using cross browser testing with TestNG and selenium we will see shortly what is selenium and TestNG.

Selenium

Selenium is a test automation framework offers browser automation support to different browsers such as chrome, edge, Firefox , IE, etc. with its browser specific Web Drivers. Selenium is very well known framework for cross browser testing. It is open source software tool for automated cross browser testing. We can create test script using selenium with single interface and programming languages like Java, C# or Python.

It is good choice to use because it comes as a software suite with different options like;

  • Selenium WebDriver

  • Selenium IDE

  • Selenium Grid


TestNG

It is open source automated framework where NG of TestNG stands for Next Generation. It help to write down more flexible and effective test with help of annotations, grouping, prioritizing , generating logs and parameterizing. With the help of @Parameters or @DataProviders of TestNG we can do Cross Browser Testing quickly. We can provide parameters in TestNG at both suite and class level. To get idea about them in following examples we are declaring one at suite level with @Paramertes annotation use and another with class level which is with @DataProvider TestNG annotation.


Overall required steps to setting up selenium for automated cross browser testing:

1) Required Dependencies :

  • Selenium Dependency

  • TestNG Dependency

  • WebDriverManager

2) Construct test automation Framework:

This framework allows to write test cases once the easily execute them across various browsers and browser version.

Required things to construct test framework:

1. Selenium client libraries provide binding for languages like JAVA , Python, C# ,etc.

2. Browser specific web drivers helps to launch and control individual browser instance.

3. TestNG as test runner we can execute full test suites across configurations. 

3) Configure web Drivers for each browser:

One important feature of automated browser testing is web drivers.

These drivers allow to produce browser instances programmatically. Configure a unique driver  for each browser in test matrix which includes information about test cases, test status, test scenarios and issues and manage them in together  as you alternate between browsers.

 Here,

  • I created reference variable for web driver.

  • Created objects for different browsers which are supported by web driver manager class.

4) Parameterize Test Methods:

Parameterizing test methods enables easy switching between configured web drivers of that browser.


After this we need to convert this class to TestNG as Testng.xml where we can get our test suite where we can construct it which will help us to execute our test class.

Test run can pass "chrome" or "firefox" to run the initialize  method against different browsers using the single shared driver instance. This technique  minimizes duplicate code when testing across multiple browsers.

5) Construct Test Suites:

Manipulate test runner framework to build cross browser test suites.


Above code snippet does the following job:

  • Initialize a parameter with the name browser which will help to pass value for browser parameter.

  • Initialize the browser driver depending on the parameter value. Means for browser value equal to Chrome, initialize a chrome driver

Execute test suite to run all test methods against all configured browsers and  drivers. This help to make scaling cross browser test coverage easy. Below snippet shows test cases passed for different browsers.

We can do Cross Browser Testing with help of Data Providers also with using @DataProvider annotation.

In above snippet code we can see;

  • We named @DataProvider as browser and passing it to the @Test

  • And then initialized the browser drivers depending on the parameter value.


After executing you can see all test cases are getting passed as shown below snippet.

Summary

Cross Browser Testing is very important and required concept which every developer or testers should aware about it, as it helps to run tests on multiple browsers simultaneously on different platforms. Cross browser testing with selenium and TestNG helps to run all our test scenarios very efficiently and quickly.



29 views

Recent Posts

See All
bottom of page