Pooja Venkitaraman February 2016

Parallel execution of two suites using web driver and Selenium

I have two testNG suites in my project. I want to run both of them in parallel.

Suite1:

class A
class B

Suite2:

class C
class D

I want to run SUITE1 and SUITE2 in parallel on the same machine. However, Class B of SUITE1 should be run only after Class A. Same with the second suite: the first and second classes need to be run in serial.

How do I achieve this?

Answers


Sanjay Bhimani February 2016

In order to achieve, you need to add annotation as @Test(priority=??). The default value will be zero for priority.

If you don't mention the priority, it will take all the test cases as "priority=0" and execute.

If we define priority as "priority=", these test cases will get executed only when all the test cases which don't have any priority as the default priority will be set to "priority=0"

You dont need two xml for your requirement. Follow these and you should have same test running parallel.

<suite name="Test-class Suite" parallel="tests" thread-count="2">
<test name="Test-class test 1">
    <classes>
        <class name="com.ClassA" />
        <class name="com.ClassB" />
    </classes>
</test>
<test name="Test-class test 2">
    <classes>
        <class name="com.ClassC" />
        <class name="com.ClassD" />
    </classes>
</test>

Make sure your parallel parameter have parallel='true' and thread-count as per your requirement.


murali seleniumtrainer February 2016

to execute classes as specified order, need to use preserve-order="true". As per below xml file, ClassB is specified first so ClassB is executed first then ClassA as we specified preserve-order="true"

If you want to execute @Test methods in class as per required order, please use priority. like below

@Test(priority=1)

below is xml file for example..

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Suite" parallel="tests" preserve-order="true">

  <test name="TestA">
    <classes>
      <class name="com.test.ClassB"/>
      <class name="com.test.ClassA"/>
    </classes>   </test> <!-- Test A--> 

 <test name="TestB">
    <classes>
      <class name="com.test.ClassD"/>
      <class name="com.test.ClassC"/>
    </classes>   </test> <!-- Test B--> 
</suite> <!-- Suite -->

*****updating as per comment

Hi,

To execute two suites, need to create two xml files and specify your suites in those xml files. Then create another xml file to call these suites xml files..

Lets say i have one suite in testng1.xml file

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
 <suite name="Suite1" parallel="false" preserve-order="true">

 <test name="TestA">
 <classes>
  <class name="com.test.NewTest1"/>
 </classes>
 </test> <!-- Test -->
</suite> <!-- Suite -->

another suite in testng2.xml file

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
 <suite name="Suite2" parallel="false" preserve-order="true">

<test name="TestB">
  <classes>
   <class name="com.test.NewTest1"/ 

Post Status

Asked in February 2016
Viewed 2,157 times
Voted 7
Answered 2 times

Search




Leave an answer