Run testng methods across different tests in parallel

1.4k views Asked by At

I have more than one test tags in my testng.xml file that I am running using maven. I have set the parallel attribute at the suite level to methods and the thread-count as 5. The problem I am facing is that the tests are executed sequentially and only the methods inside the test cases are executed in parallel. To be more clear, though there are unused threads(Selenium nodes in the grid in my case) available the subsequent tests waits till all the methods in the previous test are executed.

Here is the testng.xml that i have used,

<suite name="Suite1" verbose="1" parallel="methods" thread-count="5" preserve-order="false">
  <test name="Login" >
    <classes>
       <class name="testSuite.TestSet1" />
    </classes>
  </test>

  <test name="Product Search">
    <classes>
      <class name="testSuite.TestSet2"/>
    </classes>
  </test>
</suite>

As I have more than 10 nodes available in my selenium grid, this behavior increases the execution time considerably and defeats the purpose of having a grid architecture. Please let me know if there's a way using which I can execute the test methods across the suite in parallel. I am sure that I am missing something silly, but could you please help me point that?

3

There are 3 answers

0
Chuck Brown On BEST ANSWER
<suite name="Suite1" verbose="1" parallel="tests" thread-count="2" preserve-order="false">   
  <test name="Login" parallel="methods" thread-count="5">
    <classes>
       <class name="testSuite.TestSet1" />
    </classes>   
  </test>
  <test name="Product Search" parallel="methods" thread-count="5">
    <classes>
      <class name="testSuite.TestSet2"/>
    </classes>   
  </test> 

First allow your Suite to run "tests" in parallel with the number of test suites to run at a time (example 2).

Second allow your test to run "methods" parallel with the number of methods each can run (example 5 in each).

If you are bumping against the your thread limit be careful when adjusting these numbers. For example if you add another test group with thread-count of 5 and change your suite thread-count to 3. You'll now be at 15 threads.

1
QA Automation tester On

Type parallel="tests" in your TestNG xml file

1
niharika_neo On

Parallel=methods would do exactly that - "methods inside the test cases are executed in parallel".

If you want your test tags to be executed parallely use parallel=tests.
This would run all your test tags in parallel.

But you state you have 10 nodes available. If above is the only xml you have then only two nodes would be used up at a time since you have just two test tags.