TestNG XML DTD错误

时间:2017-09-29 08:45:57

标签: java xml testng xml-dtd

我正在使用testng xml运行selenium脚本,但到目前为止,一切正常,但现在它总是抛出错误,但是当我删除第一行时,它正在处理警告

TestNG xml文件如下

<!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>

并抛出错误

 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

2 个答案:

答案 0 :(得分:1)

您的套件xml文件格式不正确。 <listeners>代码中不应包含<test>标记。

这是正确的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>

答案 1 :(得分:0)

标签的顺序错位,所以在这里找到我的答案

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

应将

侦听器添加到测试名称上方或套件名称下方。