BrowserStack : Parallel Testing [ 2024 ]
BrowserStack: Parallel Testing
This post will show us how to perform parallel testing using BrowserStack.We will run a sample test case with 2 threads. BrowserStack is a cloud-based testing platform that allows developers to test their websites and mobile applications across various browsers, operating systems, and devices. It provides real-time, on-demand testing environments for both manual and automated testing.
A sample test case opens a Bing search page, searches for “HelloWorld,” and asserts for the title.
Sample Code
package com.testingdocs.sample.framework.tests; import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; import org.testng.annotations.Test; public class SampleTest extends CloudSetUp { @Test public void sampletest() throws Throwable { driver.get("https://www.bing.com"); driver.findElement(By.id("sb_form_q")).sendKeys("HelloWorld"); driver.findElement(By.id("sb_form_go")).click(); WebDriverWait wait = new WebDriverWait(driver, 60); wait.until(ExpectedConditions.titleContains("Hello")); Assert.assertEquals("HelloWorld - Bing", driver.getTitle()); driver.quit(); } }
We will run the tests in parallel . We need to specify parallel=”tests” in the TestNG suite file.Additionally, we need to specify thread-count parameter. thread-count parameter specifies the number of threads.
CloudSetUp class should have the implementation to get the RemoteWebDriver instance pointing to BrowserStack.
Sample TestNG suite file
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="SampleSuite" verbose="0" parallel="tests" thread-count="2"> <test name="FirefoxTest"> <parameter name="browser" value="Firefox" /> <parameter name="browser_version" value="46" /> <parameter name="os" value="Windows" /> <parameter name="os_version" value="10" /> <parameter name="view" value="Desktop" /> <classes> <class name="com.testingdocs.sample.framework.tests.SampleTest" /> </classes> </test> <test name="InternetExplorerTest"> <parameter name="browser" value="IE" /> <parameter name="browser_version" value="10" /> <parameter name="os" value="Windows" /> <parameter name="os_version" value="7" /> <parameter name="view" value="Desktop" /> <classes> <class name="com.testingdocs.sample.framework.tests.SampleTest" /> </classes> </test> </suite>
Note that if you have any error in the syntax of TestNG suite file , you might get exceptions while running the suite file .
Sample exception
org.testng.TestNGException: java.lang.NullPointerException at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:325) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:109) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81) Caused by: java.lang.NullPointerException at org.testng.xml.TestNGContentHandler.xmlClasses (TestNGContentHandler.java:349) at org.testng.xml.TestNGContentHandler.endElement (TestNGContentHandler.java:716) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement (Unknown Source) at com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator. endNamespaceScope(Unknown Source) at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator. handleEndElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement (Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl. scanEndElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl. XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next (Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl. next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl. scanDocument(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse (Unknown Source) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse (Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser .parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse (Unknown Source) at javax.xml.parsers.SAXParser.parse(Unknown Source) at org.testng.xml.XMLParser.parse(XMLParser.java:39) at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16) at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9) at org.testng.xml.Parser.parse(Parser.java:172) at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:305) ... 3 more
Run the suite file as TestNG suite and log in to the BrowserStack account.
One test runs on Firefox, Windows 10 environment.
Another test runs on Internet Explorer, Windows 7 environment.
Selenium Tutorials
Selenium WebDriver Tutorials on this website can be found at:
For more details on the Selenium, visit the official website at:
BrowserStack official website: