Site icon TestingDocs.com

BrowserStack : Parallel Testing

Overview

In this post, we will see how to perform parallel testing using BrowserStack.We will run a sample test case with 2 threads.

Sample testcase used to run. The sample testcase opens a Bing search page and searches for “HelloWorld” and asserts for title .

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 login to BrowserStack account .

One test runs on Firefox , Windows 10 environment.

Another test runs on Internet Explorer , Windows 7 environment.

 

Selenium WebDriver Tutorials on this website can be found at:

https://www.testingdocs.com/selenium-webdriver-tutorial

For more details on the Selenium, visit the official website at:

https://www.selenium.dev/

Exit mobile version