TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Selenium

    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/

    Related Posts

    Windows 10 Settings

    Selenium /

    Add Microsoft Webdriver on Windows OS

    Download Selenium Components

    Selenium /

    Getting Started with Selenium Webdriver

    LambdaTest Testing Cloud SaaS Platform

    Selenium /

    LambdaTest – Testing Cloud SaaS Platform

    Selenium /

    Selenium 3.0 and Mozilla GeckoDriver

    SauceLabs Website

    Selenium /

    Run an Example Test on SauceLabs

    ‹ Selenium WebDriver Architecture› Selenium FluentWait Example

    Recent Posts

    • ChatGPT Subscription Plans
    • Stellar Converter for Database
    • Stellar Log Analyzer for MySQL
    • Stellar Repair for MySQL
    • ChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI Features
    • Shaping the Future of Development: Exploring Key Trends in Software Engineering
    • Improving Java Performance with Multithreading
    • Open-source Vector Databases

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com