I am writing a content to TestNG file using java. The reason behind writing the testng.xml file is to add <test>...</test>
dynamically to the file.
I am using BufferedWriter to write the content in the xml file.
After creating the file using below code to run the testng.xml file
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add(FILENAME);// path to testng.xml
testng.setTestSuites(suites);
testng.run();
When I ran the javacode it prompts below error:
Exception in thread "main" org.testng.TestNGException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:324)
at org.testng.TestNG.run(TestNG.java:1101)
at com.MOKA.TestModules.MasterDriver.main(MasterDriver.java:100)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.testng.xml.XMLParser.parse(XMLParser.java:39)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9)
at org.testng.xml.Parser.parse(Parser.java:170)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:304)
... 2 more
Again, if I run same generated testng.xml using "Run as TestNG Suite" it runs successfully
Reference, below is the testng.xml content
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://ift.tt/19x2mI9">
<suite name="Test_Automation">
<test name="Module 3">
<classes>
<class name="com.TestModules.TestScenarios_Module_3"/>
</classes>
</test> <!-- Test -->
<test name="Module 4">
<classes>
<class name="com.TestModules.TestScenarios_Module_4"/>
</classes>
</test> <!-- Test -->
<test name="Module 7">
<classes>
<class name="com.TestModules.TestScenarios_Module_7"/>
</classes>
</test> <!-- Test -->
</suite>
Aucun commentaire:
Enregistrer un commentaire