TestNG XML configuration file DTD "test" tag error

24,449

Solution 1

Apparently the order of the elements are important. First comes the parameters, then groups, and classes should be the last element in the test element. That's the correct format of configuration file:

<suite name="tests" allow-return-values="true"
    verbose="10">
    <test name="Bing-Search-Sample-Test">
        <parameter name="testInterfaceXML" value="SearchInterface.xml"></parameter>
        <parameter name="testSuiteXML" value="SearchTest.xml"></parameter>
        <groups>
            <run>
                <include name="sample-tests" />
            </run>
        </groups>
        <classes>
            <class name="package.TestFactory" />
        </classes>
    </test>
</suite>

Solution 2

Simply change the first line with following:

<?xml version="1.0" encoding="UTF-8"?>

Remove this line :

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

It will not show error.

Solution 3

Simpily replace below lines:

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

With:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-2.4.dtd"> 

It worked for me.

Reference: https://www.experts-exchange.com/questions/23176057/web-xml-Element-type-listener-must-be-declared.html

Solution 4

One common use of validation is to ensure that software knows what to expect from the input, so as to guarantee that every valid document will be correctly handled. There is not always a guarantee that every invalid document will raise an error -- sometimes (as here) some consuming software can in fact handle some documents that aren't valid.

You ask if the fact that the software handles your input correctly means that there is something wrong with the DTD. Not necessarily: it's quite often easier to define a strict ordering than to allow for all possible variations in ordering, particularly when the order of elements does not convey information.

Share:
24,449
atavakoli
Author by

atavakoli

Updated on July 01, 2020

Comments

  • atavakoli
    atavakoli almost 4 years

    I have always getting this error for test tag (at line test name="Bing-Search-Sample...) in TestNG XML configuration file, when eclipse is trying to validate the XML against its DTD. The file is working fine and seems to have no problems:

    The content of element type "test" must match "(method-selectors?,parameter*,groups?,packages?,classes?)".

    XML File:

    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
    
    <suite name="tests" allow-return-values="true"
        verbose="10">
        <test name="Bing-Search-Sample-Test">
            <classes>
                <class name="package.TestFactory" />
            </classes>
            <groups>
                <run>
                    <include name="sample-tests" />
                </run>
            </groups>
            <parameter name="testInterfaceXML" value="SearchInterface.xml"></parameter>
            <parameter name="testSuiteXML" value="SearchTest.xml"></parameter>
        </test>
    </suite>
    

    Since the XML is working fine, I am wondering if there is a problem with TestNG DTD or in the XML file validation with eclipse.