2

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 -->
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Danesh
  • 45
  • 10

2 Answers2

1

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.

Monolith
  • 1,067
  • 1
  • 13
  • 29
user861594
  • 5,733
  • 3
  • 29
  • 45
  • Thank you. i could see a message as **Last unit does not have enough valid bits**. as a result, my test scripts are getting failed. Moreover, i am executing my test scripts using Remote Web driver – Danesh Mar 17 '19 at 18:15
  • `Last unit does not have enough valid bits` message doesn't looks related to TestNG/webdriver or parallel execution. Will you please provide detailed console log? – user861594 Mar 18 '19 at 01:14
  • i am getting **'Error communicating with the remote browser. It may have died.' ** message when i run it. If i run though debug mode, it's running successfully. How is it ? – Danesh Mar 18 '19 at 14:17
  • It looks different issue then the original question. You may check existing questions related to webdriver issue or ask another separate question explaining webdriver problem. If this happens when you running in parallel, you need to make sure thread safe driver instance. Few of the time people using static driver which will not work with parallel execution. Framework like QAF will ensure thread safe driver. Again this is separate discussion then the original question. – user861594 Mar 19 '19 at 00:44
  • Thank you so much... I did few more analysis on thread safety and got the solution finally... – Danesh Mar 20 '19 at 16:30
0

Well for one thing pubic is not a scope :)--you've also got some more incorrect syntax in there. The space after your the Object in your dataprovider shouldn't be there, the function signature should be

public Object[][] Execution() throws IOException {
     return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}

Next, the argument in your TestExecution method is defined incorrectly.

public void TestExecution(String arg) {
    // Execute your tests
}

Finally, you've got to capitalize the 'p' in DataProvider whenever you use it. So that leaves us with

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

At this point I'm not sure what problem(s) remain(s). Is this something like what you were looking for? Let me know if this does or doesn't help.

C. Peck
  • 3,641
  • 3
  • 19
  • 36
  • Thank you. Actually it was my mistake and i should have made it more clear. Typo. i could run parallel using user861594 comments. But i am getting error as **'Last unit does not have enough valid bits'** – Danesh Mar 17 '19 at 18:12