How to execute more than 1 xml file in PARALLEL with TestNG

5,504 views
Skip to first unread message

Manoj Kapuganti

unread,
Aug 8, 2012, 10:20:46 AM8/8/12
to testng...@googlegroups.com
Hi All,

I want to execute multiple xml files (Example: 2 xml files) in parallel with eclipse.

Is there a way to achieve this alone with Eclipse & TestNG.

Best Regards,
Manoj Kapuganti

吴亭

unread,
Aug 8, 2012, 10:32:43 AM8/8/12
to testng...@googlegroups.com
Hi  Manoj,

Maybe you can try like this:

        TestNG ng = new TestNG();
        ng.setXmlSuites([A list include your xml files]);
        ng.setSuiteThreadPoolSize(3);
        ng.run();

Br,
Tim
2012/8/8 Manoj Kapuganti <manoj...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/c-u6qNRWZNsJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Manoj Kapuganti

unread,
Aug 8, 2012, 2:12:11 PM8/8/12
to testng...@googlegroups.com
Hi Tim,

Thanks for you reply.

Could you please let me know how to use above code. Do I need to use listeners. If yes give me briefly.

Best Regards,
Manoj Kapuganti

Manoj Kapuganti

unread,
Aug 8, 2012, 4:21:35 PM8/8/12
to testng...@googlegroups.com
Hello Tim,

Thank you so much for your help.

Now I am able to execute multiple xml files in parallel.

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.testng.xml.Parser;
import org.testng.xml.XmlSuite;
import org.testng.TestNG;
import org.xml.sax.SAXException;

public class MultipleXmls{

public static void main(String[] args) throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
TestNG testng = new TestNG(); 
testng.setXmlSuites((List <XmlSuite>)(new Parser("G:\\ManojKS\\Eclipse workspace\\Test1.xml").parse()));
testng.setSuiteThreadPoolSize(3);
testng.run();
    }
}

In Test1.xml content is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Suites"> 
  <suite-files>
  <suite-file path="G:\ManojKS\Eclipse workspace\systemSettings\atest1.xml" />
  <suite-file path="G:\ManojKS\Eclipse workspace\systemSettings\atest2.xml" />
  <suite-file path="G:\ManojKS\Eclipse workspace\systemSettings\atest3.xml" />
  </suite-files>
</suite>

Thank you so much for your help again.

Best Regards,
Manoj Kapuganti

吴亭

unread,
Aug 8, 2012, 9:27:35 PM8/8/12
to testng...@googlegroups.com
Hi Manoj,

You are welcome, glad to hear the good news :)

Br,
Tim

2012/8/9 Manoj Kapuganti <manoj...@gmail.com>

Best Regards,
Manoj Kapuganti

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/0bVJ5zQL3VsJ.

Krishnan Mahadevan

unread,
Aug 8, 2012, 9:35:57 PM8/8/12
to testng...@googlegroups.com
Tim,
Am curious to know:

1.  How do you do this via the TestNG xml suite file [without using the TestNG APIs]
2.  How do you determine that the suites are INDEED running in parallel ? [Thread.getCurrentThread().getId() ?  I see the suites run in parallel when i merely enable parallelism at every suite level itself. So trying to understand the relevance and difference ]

would you happen to know ?


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

吴亭

unread,
Aug 8, 2012, 10:41:07 PM8/8/12
to testng...@googlegroups.com
Hi  Krishnan ,

For Q1, I do not know how to do this though the xml files, according to the documents of testng, do not find related contents.

For Q2,  I do not try this before, I just provide a possible solution according the meaning of API. :) Thanks for your reminder, I need have a try for this.

Br,
Tim

2012/8/9 Krishnan Mahadevan <krishnan.ma...@gmail.com>

Rao

unread,
Nov 1, 2012, 6:08:09 AM11/1/12
to testng...@googlegroups.com
Hello Manoj,

Are you using Grid 2.0 to run your Sites parallel??and also please tell me can we generate XSLT reports when running TestNG programatically ??

Please advise me

Advanced Thanks

Rao

Manoj Kapuganti

unread,
Nov 1, 2012, 9:13:34 AM11/1/12
to testng...@googlegroups.com
Hello Rao,

I am not using Grid.

By using testng.setSuiteThreadPoolSize(10) we can run 10 suites in parallel.

Please see the post on Aug 9, all details including script was pasted over there.

I am not aware of XSLT reports.

Let me know if you need any other details

Best Regards,
Manoj Kapuganti

Rao

unread,
Nov 1, 2012, 11:29:56 AM11/1/12
to testng...@googlegroups.com
Hello Manoj

Thanks for quick reply, In my TestBase class (I am running my suites parallel in multiple browsers by reading Browser parameter from XML file)

@Parameters ({"browsername"} )
public void openBrowser(String browser) throws MalformedURLException{
if (!isBrowserOpened) {
driver = new ThreadLocal<RemoteWebDriver>();
DesiredCapabilities dc = new DesiredCapabilities();
if (browser.equalsIgnoreCase("firefox")){
dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
driver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc));
}
if (browser.equalsIgnoreCase("iexplorer")){
dc.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName());
driver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc));
}

if (browser.equalsIgnoreCase("chrome")){
dc.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
driver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc));
}
isBrowserOpened = true;
}
}

My XML file is like below

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Selenium2 Grid with webdriver2" verbose="3" parallel="classes" thread-count="4" >
  <test name="Test LG04" >
<parameter name="browsername" value="chrome" />
    <classes>
      <class name="com.exony.test.framework.login.TestCase_LG04" />
    </classes>
   
  </test>
  <test name="Test LG04_FireFox">
    <parameter name="browsername" value="firefox" />
    <classes>
      <class name="com.exony.test.framework.login.TestCase_LG04" />
    </classes>
  </test>
  <!-- <test name="Test LG06">
<parameter name="browsername" value="firefox"/> 
   <classes>
        <class name="com.exony.test.framework.login.TestCase_LG04" ></class>  
</test>
</suite>


In the above xml file i am specifying the same class to run in both browsers at a time. Manoj, do you know how can specify in TestNg.Xml to run the Suites in multiple browsers at a time. please help me with this

Advanced Thanks

Rao


Manoj Kapuganti

unread,
Nov 2, 2012, 3:20:00 PM11/2/12
to testng...@googlegroups.com
Hello Rao,

Please use below Xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Selenium2 Grid with webdriver2" verbose="3" parallel="tests">

<test name="Test LG04" >
<parameter name="browsername" value="chrome" />
    <classes>
      <class name="com.exony.test.framework.login.TestCase_LG04" />
    </classes>
</test>

  <test name="Test LG04_FireFox">
    <parameter name="browsername" value="firefox" />
    <classes>
      <class name="com.exony.test.framework.login.TestCase_LG04" />
    </classes>
</test>

<test name="Test LG06">
<parameter name="browsername" value="firefox"/> 
   <classes>
        <class name="com.exony.test.framework.login.TestCase_LG04" ></class>  
</test>

</suite>

Rightclick on xml file, choose Run as TestNG. By executing this all 3 tests will start in parallel.

Here you are using only 1 suite. But your in your question you said to execute multiple suites...

Please let me know if you have any queries.

Best Regards,
Manoj Kapuganti

mummana subramanya

unread,
Jun 28, 2013, 12:24:25 AM6/28/13
to testng...@googlegroups.com
thanks to uh and especially tim for providing the solution for parallel execution of test suites :) before parallel execution it took 5mins approx to complete the all test cases since m using selenium grid its getting completed  with 3 mins :)

Saptha Rishi

unread,
Sep 18, 2013, 8:27:54 AM9/18/13
to testng...@googlegroups.com
Hi Manoj,
             I used the same code as you mentioned but i am facing nullpointerexception, i am new to Testng, kindly help me in this regard
package programs;

java code:


import java.io.IOException;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;

import org.testng.TestNG;
import org.testng.xml.Parser;
import org.testng.xml.XmlSuite;
import org.xml.sax.SAXException;

public class Multiplexmls {
   
    public static void main(String args[]) throws ParserConfigurationException, SAXException, IOException

    {
        TestNG testng = new TestNG();
        testng.setXmlSuites((List <XmlSuite>)(new Parser("C:\\Users\\SRI\\Desktop\\eclipse\\eclipse\\Workspace\\FirstTestNG\\Mainfile.xml").parse()));
        testng.setSuiteThreadPoolSize(3);
        testng.run();
    }
 
}

TestNG file:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="All test">
<suite-files>
<suite-file path="C:\Users\SRI\Desktop\eclipse\eclipse\Workspace\FirstTestNG\grouptest.xml"/>
<suite-file path="C:\Users\SRI\Desktop\eclipse\eclipse\Workspace\FirstTestNG\testng.xml"/>
</suite-files>
</suite>

ERROR LOG:

Exception in thread "main" java.lang.NullPointerException
    at org.testng.xml.XmlTest.init(XmlTest.java:77)
    at org.testng.xml.XmlTest.<init>(XmlTest.java:68)
    at org.testng.xml.TestNGContentHandler.xmlTest(TestNGContentHandler.java:256)
    at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:508)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:745)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1323)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1277)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3065)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:881)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
    at org.testng.xml.Parser.parse(Parser.java:172)
    at programs.Multiplexmls.main(Multiplexmls.java:18)


Regards,
Saptha Rishi.M

-------------------------------------------------------------------------------------------

Saptha Rishi

unread,
Sep 27, 2013, 1:16:01 AM9/27/13
to testng...@googlegroups.com
Friends pls help me with this, its easy to solve for experts like you, and it's all ready solved one but i am using the same code as Manoj mentioned , but facing the nullpointerexception.

kindly help me in this regard.

Regards,
Rishi

Himanshu Shekhar

unread,
Jan 10, 2014, 12:17:57 AM1/10/14
to testng...@googlegroups.com
Hello Saptha,

If you are still facing the same error, could you please try running again after making the following changes:
  • Replace  testng.setSuiteThreadPoolSize(3); to  testng.setSuiteThreadPoolSize(2); since in your case you are using just two test suites.
Himanshu

sajesh nair

unread,
May 15, 2015, 9:49:15 AM5/15/15
to testng...@googlegroups.com
HI Manoj,

I am looking for same solution, but the interesting part I would like to hear from you is How can I achieve the same with Selenium Grid and Ant run.
Appreciate your feedback, thanks in adv.

-
Sajesh

Ss Raghavan

unread,
May 20, 2015, 9:38:59 AM5/20/15
to testng...@googlegroups.com
Hi ,

What is suite of suites, and the parent suite has parallel=true and each suite has parallel enabled?
Tim

2012/8/9 Manoj Kapuganti <manoj...@gmail.com>
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Krishnan Mahadevan

unread,
May 21, 2015, 12:03:57 AM5/21/15
to testng...@googlegroups.com
What exactly are you looking for Raghavan ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.

To post to this group, send email to testng...@googlegroups.com.

MCK

unread,
Nov 12, 2015, 9:54:07 AM11/12/15
to testng-users
Hi Manoj, 

I used the same below code but i get the following error

Two suites cannot have the same name: Test, where as both sub xml have different suite name, What i Observe is it all the iteration it is picking only first xml and it throws this error.

testng.setXmlSuites((List <XmlSuite>)(new Parser("G:\\ManojKS\\Eclipse workspace\\Test1.xml").parse())); Is this line iterates all xmls properly

Any help on this is really appreciated

Thanks and Regards,
Sayed MCK

On Thursday, 9 August 2012 01:51:35 UTC+5:30, Manoj Kapuganti wrote:

Krishnan Mahadevan

unread,
Nov 13, 2015, 1:52:49 AM11/13/15
to testng...@googlegroups.com
Sayeed,

That error message is self explanatory. Please ensure that the name attribute of your <suite> tag all have unique names and that there are no duplications. That should fix your problem.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.

kishore.ch...@orangescape.com

unread,
Apr 18, 2016, 1:21:45 AM4/18/16
to testng-users
Hi It worked for me ,try the below code

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;

import org.testng.xml.Parser;
import org.testng.xml.XmlSuite;
import org.testng.TestNG;
import org.xml.sax.SAXException;

public class MultipleXmls {
public static void main(String[] args){
try{
TestNG testng = new TestNG(); 
testng.setTestSuites(Arrays.asList(new String[] {"D:/Auto/two/src/two/main.xml"}));
testng.setSuiteThreadPoolSize(2);
testng.run();
}catch(Exception ex){
ex.printStackTrace();
}
    }

}
 

Mohan Kumar

unread,
Aug 21, 2017, 12:51:44 PM8/21/17
to testng-users
Hi All,

I am facing the same problem, when I have single test in two testng.xml(testng1.xml & testng2.xml) files means, browsers are launched simultaneously. 

But when I have more than one test in two testng.xml files means, testng2.xml file gets triggered only after testng1.xml file gets completed. 

Please check the below example.

testng1.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Parallel suite 1" >
  <test name="Functional_Test_1">
   <parameter name="browser" value="Chrome" />
    <classes>    
      <class name="com.simpletest.sample1"/>
    </classes> 
  </test> 

   <test name="Functional_Test_2">
    <classes>    
       <class name="com.simpletest.sample2"/>
     </classes> 
  </test> 
</suite>

testng2.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Parallel suite 2" >
  <test name="Functional_Test_3">
   <parameter name="browser" value="Chrome" />
    <classes>    
      <class name="com.simpletest.demo1"/>
    </classes> 
  </test> 

   <test name="Functional_Test_4">
     <classes>    
       <class name="com.simpletest.demo2"/>
     </classes> 
  </test> 
</suite>

combinesuite.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="suite of suites"  parallel="classes" thread-count="2" >
    <suite-files>
        <suite-file path="testng1.xml" />
        <suite-file path="testng2.xml" />
    </suite-files>
</suite>


Kindly help me out to fix this issue.

Krishnan Mahadevan

unread,
Aug 21, 2017, 12:58:20 PM8/21/17
to testng...@googlegroups.com

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <testng...@googlegroups.com> on behalf of Mohan Kumar <smkum...@gmail.com>
Reply-To: <testng...@googlegroups.com>
Date: Monday, August 21, 2017 at 4:43 PM
To: testng-users <testng...@googlegroups.com>
Subject: Re: [testng-users] How to execute more than 1 xml file in PARALLEL with TestNG

 

Hi All,

--

You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.

balu RPA

unread,
Nov 9, 2017, 3:58:06 AM11/9/17
to testng-users
Hi All,

This has to run as java application, but TESTNG report will not be generated.

thanks
Reply all
Reply to author
Forward
0 new messages