In this tutorial, we will be studying about multi browser testing and its implementation in Selenium. For this we will integrate Selenium with TestNG and use @Parameter annotation of TestNG to parameterize the test script with different values of browser. Also, note that multi browser testing can be carried out using Selenium Grid as well. But here, we will be using TestNG and Selenium WebDriver only for implementing multi browser testing.
Multi browser testing or cross browser testing is a type of testing in which the application under test is tested with multiple supported browsers. The need for multi browser testing arises from the fact that different browsers have different UI implementations. So, one cannot ensure that application running on Chrome will also run on IE without any issues.
Multi browser testing can be carried out in Selenium by parameterizing the browser variable. For parameterizing the browser variable we can use the @Parameter annotation of TestNG. Using the @Parameter annotation, we can pass different values of browser to the test scripts from the testng.xml file. The value of the browser parameter can then be used to instantiate the corressponding driver class of Selenium WebDriver.
As the browser value is used across all the test methods so, it is better to use the browser variable in @BeforeTest method.
The beforeTest method with @Parameter of TestNG will look like-
As stated earlier, the value of the browser variable will be passed to the test scripts through testng.xml file. This testng.xml file will have a parameter tag containing the browser variable and its value. Here, we will create two tests, one each for Firefox and Chrome browser with different browser values. Refer to the below snippet of testng.xml file to understrand the test parameterization concept. Also note that having parallel="tests" in the Suite tag makes the two tests run in parallel.
On executing the test using testng.xml, the test will run in parallel for all the specified browsers(Firefox and Chrome in case of our example).