logo logo

Compatibility Testing Using BrowserStack & Selenium – TestNG

What is Compatibility Testing?

Compatibility testing is a non-functional test to ensure that an application’s compatibility within different environments such various web browsers with various versions, Operating Systems (Windows, Linux, Mac…). In order to pass this test, we also need to check Forward and Backward Compatibility. Here I’m using Browserstack to perform Compatiblity testing.

BrowserStack allows users to make manual and automation testing on different browsers and operation systems.To execute your test scripts using BrowserStack, you need to set parameters of Browsers and Platforms. There are few steps to be followed to integrate Selenium with BrowserStack:

Step 1 : SignUp for BrowserStack account (Free Trail)
Step 2 : Get your UserName and Access Key (Click on Account at the top and click on ‘Automate‘)
Step 3 : Create your Test scripts using TestNG
Step 4 : Create a TestNG.xml file to run tests in parallel (set platforms and browsers with desired versions).
Step 5 : Execute TestNG.xml.
Step 6 : To view your results, Login and click on ‘Automate‘ link. You can view your project results.

Here I’m providing a sample code. I’m using TestNG to run tests in parallel.

package package1;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class BrowserStackTestCase {

private WebDriver driver;
public static final String USERNAME = “YourUserName”;
public static final String AUTOMATE_KEY = “YourAccessKey”;
public static final String URL = “http://browserstack.com; + USERNAME + “:” + AUTOMATE_KEY
+ “@hub.browserstack.com/wd/hub”;

@Parameters(value = { “browser”, “version”, “platform” })
public void setUp(String browser, String version, String platform)
throws Exception {
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(“platform”, platform);
capability.setCapability(“browserName”, browser);
capability.setCapability(“browserVersion”, version);
capability.setCapability(“project”, “MyProject”);
capability.setCapability(“build”, “2.01”);
driver = new RemoteWebDriver(new URL(URL), capability);

@Test(priority = 1)
public void testcase001() throws Exception {
System.out.println(“Page title : ” + driver.getTitle());
Assert.assertEquals(“Google”, driver.getTitle());
WebElement element = driver.findElement(By.name(“q”));
element.sendKeys(“Merry christmas”);


@Test(priority = 2)
public void testcase002() {
System.out.println(“Page title : ” + driver.getTitle());
Assert.assertEquals(“Selenium – Web Browser Automation”,

public void takeScreenShot(ITestResult result) {
if (result.getStatus() == ITestResult.FAILURE) {
driver = new Augmenter().augment(driver);

File srcFile = ((TakesScreenshot) driver)
try {
FileUtils.copyFile(srcFile, new File(“D:\\Screenshot”
+ result.getParameters().toString() + “.png”));
} catch (IOException e) {

public void tearDown() throws Exception {


Now setup your configuration in xml file. Copy the below code.

<suite thread-count=”3″ name=”Suite” parallel=”tests”>
<test name=”FirstTest”>
<parameter name=”browser” value=”firefox” />
<parameter name=”version” value=”38″ />
<parameter name=”platform” value=”Windows” />
<class name=”package1.BrowserStackTestCase” />
<test name=”SecondTest”>
<parameter name=”browser” value=”safari” />
<parameter name=”version” value=”6.0″ />
<parameter name=”platform” value=”MAC” />
<class name=”package1.BrowserStackTestCase” />
<test name=”ThirdTest”>
<parameter name=”browser” value=”Internet Explorer” />
<parameter name=”version” value=”11″ />
<parameter name=”platform” value=”Windows” />
<class name=”package1.BrowserStackTestCase” />

That’s it, your Testcases were executed. Just login and click on ‘Automate’ link and you will see your results.

Have you done Compatibility testing using Selenium and BrowserStack before?

What is your opinion about performing compatibility testing this way? 😉




About the author

Hari Charan


8 5 comments
  • yatindra456 October 10, 2016, 7:32 pm

    I am not getting any ‘Automate’ link after login..please help me out

  • Asya Galinsky February 27, 2017, 2:54 pm

    BrowserStack has made some changes these days so the objective of this step is to get an access key.

  • [email protected] March 21, 2017, 10:03 pm

    When i run the testng.xml file i get this error: Exception in thread “main” java.lang.NoClassDefFoundError: org/testng/remote/RemoteArgs

    Please help I have been stuck for a while at this.
    Great blog.

    • Hari Charan March 23, 2017, 3:55 pm

      Exception is due to TestNG jar is missing from the dependencies or it was corrupted. Get the latest testNG jar and add it to the classpath. If you’re using Maven then get it from central repo. I assume you’ve configured Maven correctly. Cross check settings.xml in .m2 folder has been modified?

  • Dmytro Makieiev April 11, 2017, 8:53 pm

    Hi Harl, Thank you for your article.
    I have a question more related to TestNG itself
    Is there way instead of hardcoding list of browsers in xml

    pass them from the other file or even from outside of framework
    Thank you.

Leave a Reply