Compatibility Testing Using BrowserStack & Selenium – TestNG
Compatibility Testing is a type of Software testing to check whether your software is capable of running on different hardware, operating systems, applications , network environments or Mobile devices.
Compatibility Testing is a type of the Non-functional testing
BrowserStack allow us to make automation testing on different platforms at once place.
You need to set few parameters browsers and platforms. There are few steps to be followed to integrate Selenium with BrowserStack.
You need to set few parameters browsers and platforms. There are few steps to be followed to integrate Selenium with BrowserStack.
Step1: Sign Up for BrowserStack account
Step2: Get your username and access key.
Step3: Create your test script using TestNG
Step4: Create your testng.xml file to run your test in parallel
Step5: Execute testng.xml
Step6: To view your result, login and click on automate link, so that you can view your project result.
Step2: Get your username and access key.
Step3: Create your test script using TestNG
Step4: Create your testng.xml file to run your test in parallel
Step5: Execute testng.xml
Step6: To view your result, login and click on automate link, so that you can view your project result.
Here is sample code that I am providing written using TestNG.
public class BSTC {
private WebDriver driver;
public static final String USERNAME = “<usename>”;
public static final String AUTOMATE_KEY = “<accesskey>”;
public static final String URL = “http://browserstack.com; + USERNAME + “:” + AUTOMATE_KEY
+ “@hub.browserstack.com/wd/hub”;
public static final String USERNAME = “<usename>”;
public static final String AUTOMATE_KEY = “<accesskey>”;
public static final String URL = “http://browserstack.com; + USERNAME + “:” + AUTOMATE_KEY
+ “@hub.browserstack.com/wd/hub”;
@BeforeTest
@Parameters(value = { “browser”, “version”, “platform” })
@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)
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(“platform”, platform);
capability.setCapability(“browserName”, browser);
capability.setCapability(“browserVersion”, version)
capability.setCapability(“project”, “TestProject”);
capability.setCapability(“build”, “3.03”);
driver = new RemoteWebDriver(new URL(URL), capability);
}
capability.setCapability(“build”, “3.03”);
driver = new RemoteWebDriver(new URL(URL), capability);
}
@Test(priority = 1)
public void TC01() throws Exception {
driver.get(“http://www.google.com;);
Assert.assertEquals(“Google”, driver.getTitle());
WebElement element = driver.findElement(By.name(“q”));
element.sendKeys(“BrowserStack”);
element.sendKeys(Keys.ENTER);
public void TC01() throws Exception {
driver.get(“http://www.google.com;);
Assert.assertEquals(“Google”, driver.getTitle());
WebElement element = driver.findElement(By.name(“q”));
element.sendKeys(“BrowserStack”);
element.sendKeys(Keys.ENTER);
}
@Test(priority = 2)
public void TC02() {
driver.get(“http://seleniumhq.org;);
Assert.assertEquals(“Selenium – Web Browser Automation”,
driver.getTitle());
}
public void TC02() {
driver.get(“http://seleniumhq.org;);
Assert.assertEquals(“Selenium – Web Browser Automation”,
driver.getTitle());
}
@AfterMethod
public void takeScreenShot(ITestResult result)
{
if (result.getStatus() == ITestResult.FAILURE)
{
driver = new Augmenter().augment(driver);
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(srcFile, new File(“D:\\Screenshot”+ result.getParameters().toString() + “.png”));
public void takeScreenShot(ITestResult result)
{
if (result.getStatus() == ITestResult.FAILURE)
{
driver = new Augmenter().augment(driver);
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(srcFile, new File(“D:\\Screenshot”+ result.getParameters().toString() + “.png”));
} catch (IOException e)
{
e.printStackTrace();
}
}
}
{
e.printStackTrace();
}
}
}
@AfterTest
public void tearDown() throws Exception {
driver.quit();
}
}
public void tearDown() throws Exception {
driver.quit();
}
}
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=”42″ />
<parameter name=”platform” value=”Windows” />
<classes>
<class name=”package1.BSTC” />
</classes>
</test>
<test name=”SecondTest”>
<parameter name=”browser” value=”safari” />
<parameter name=”version” value=”7.0″ />
<parameter name=”platform” value=”MAC” />
<classes>
<class name=”package1.BSTC” />
</classes>
</test>
<test name=”FirstTest”>
<parameter name=”browser” value=”firefox” />
<parameter name=”version” value=”42″ />
<parameter name=”platform” value=”Windows” />
<classes>
<class name=”package1.BSTC” />
</classes>
</test>
<test name=”SecondTest”>
<parameter name=”browser” value=”safari” />
<parameter name=”version” value=”7.0″ />
<parameter name=”platform” value=”MAC” />
<classes>
<class name=”package1.BSTC” />
</classes>
</test>
<test name=”ThirdTest”>
<parameter name=”browser” value=”Internet Explorer” />
<parameter name=”version” value=”10″ />
<parameter name=”platform” value=”Windows” />
<classes>
<class name=”package1.BSTC” />
</classes>
</test>
</suite>
<parameter name=”browser” value=”Internet Explorer” />
<parameter name=”version” value=”10″ />
<parameter name=”platform” value=”Windows” />
<classes>
<class name=”package1.BSTC” />
</classes>
</test>
</suite>
This is how, we can execute same test case in multiple environment. Just login and click on 'Automate' link and you will see your result.
All The Best...