How to run multiple xml files with TestNG

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to run multiple xml files with TestNG

Saptha Rishi
Hi friends,
               I am trying to run multiple xml files programatically,  i.e , in the program i have mentioned the location of Main.xml file where this file(Main.xml) contains the location of other xml files so it will run multiple xml files, but facing null pointer exception, kindly help me with this
CODE:
package programs;

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

import javax.xml.parsers.ParserConfigurationException;
import java.io.FileNotFoundException;
import org.testng.TestNG;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.xml.Parser;
import org.testng.xml.XmlSuite;
import org.xml.sax.SAXException;

public class Multimain {
   
    @BeforeTest
    public void setup()
    {
       
        System.out.println("the setup");
    }
   
    @AfterTest
    public void teardown()
    {
        System.out.println("close");
    }
    @Test
    public void method() 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();
   
    }

}

MAIN.XML

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

In this grouptest.xml and testng.xml are the files which has to run parallel.

ERROR:

[TestNG] Running:
  C:\Users\SRI\AppData\Local\Temp\testng-eclipse-231239530\testng-customsuite.xml

the setup
close
FAILED: method
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:260)
    at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:512)
    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.Multimain.method(Multimain.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 17 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@4d63e95: 23 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@7bf5f379: 12 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@46585e93: 12 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@3a15c018: 86 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@1e549ed0: 68 ms


Thanks,
Rishi.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.