-1

I'm running selenium script with testng xml, however till now, everything was working, but now it always throws error, however when I remove first line, it is working with warning

TestNG xml file as below

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Zero Bank" verbose="1" >
<test name="Zero_Banking">
<listeners>
       <listener class-name="com.zero.utility.Listners"/>    
  </listeners>
 <classes>
<class name = "com.zero.utility.Constants"/>
<class name = "com.zero.modules.LaunchApp"/>
<class name = "com.zero.modules.WhileTrue"/>
</classes>
</test>
</suite>

and error thrown is

 Exception in thread "main" org.testng.TestNGException: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 8; The content of element type "test" must match "(method-selectors?,parameter*,groups?,packages?,classes?)".
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:324)
    at org.testng.TestNG.run(TestNG.java:1101)
    at com.zero.modules.Startup.main(Startup.java:18)
Caused by: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 8; The content of element type "test" must match "(method-selectors?,parameter*,groups?,packages?,classes?)".
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(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.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.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
Prasad_Joshi
  • 642
  • 3
  • 13
  • 34
  • For the sake of future programmers trying to write helpful error messages, can you explain how the message ''The content of element type "`test`" must match "`(method-selectors?, parameter*, groups?, packages?, classes?)"` managed to fail to draw your attention to the content of your `test` element and fail to check whether its sequence of children matched the pattern? – C. M. Sperberg-McQueen Oct 04 '17 at 17:35

2 Answers2

1

Your suite xml file format is incorrect. <listeners> tag should not be included within the <test> tag.

Here's the correct xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Zero Bank" verbose="1">
    <listeners>
        <listener class-name="com.zero.utility.Listners"/>
    </listeners>

    <test name="Zero_Banking">
        <classes>
            <class name="com.zero.utility.Constants"/>
            <class name="com.zero.modules.LaunchApp"/>
            <class name="com.zero.modules.WhileTrue"/>
        </classes>
    </test>
</suite>
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
0

Order of the tag was misplaced, so found my answer here

https://stackoverflow.com/a/37784347/5967122

listeners should be added above the test name or just below the suite name.

Prasad_Joshi
  • 642
  • 3
  • 13
  • 34