TestNG XML DTD 错误

TestNG XML DTD error

我是 运行 带有 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

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

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

您的套件 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>