seleniumselenium-webdrivertestngtestng-dataprovidertestng.xml

How to run test cases in parallel?


I have one @Test method and I am getting the Test case names from @Dataprovider. I need to run the test cases in parallel:

@Test(dataprovider="testdataprodivder")
public void TestExecution(String arg 1)
{
/* Read the testcases from dataprovider and execute it*/
}
@Dataprovider(name="testdataprodivder")
public Object [][]Execution() throws IOException
{
return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}

If I want to run the test cases in parallel i.e if I want to execute " Developer Team lead", "QA", "Business Analyst", "DevOps Eng", "PMO" in parallel what should I do?

5 browsers - Each running different test cases.

TestNG XML:

<suite name="Smoke_Test" parallel="methods" thread-count="5"> 
<test verbose="2" name="Test1">
<classes>
  <class name="Packagename.TestName"/>
</classes>
</test> <!-- Default test -->  
</suite> <!-- Default suite -->

Solution

  • In order to run data-driven test in parallel, you need to specify parallel=true in @DataProvider. For instance:

    @Dataprovider(name="testdataprodivder", parallel=true)
    public Object [][]Execution() throws IOException
    {
    return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
    }
    

    To specify thread count used by data-driven test, you can specify data-provider-thread-count (defaults to 10). For example:

    <suite name="Smoke_Test" parallel="methods" thread-count="5" data-provider-thread-count="5"> 
    
    

    NOTE: To set parallel behavior dynamically for data driven test outside code, you can use QAF-TestNG extension where you can set behavior using global.datadriven.parallel and <test-case>.parallel properties for data-provider.