TestNG XML file and error messages

04 January, 2014
This is my sample TestNG file:


<suite name="Production checklist">  
  <parameter name="googleURL" value="http://google.com">  
  <parameter name="gmailURL" value="http://gmail.com">  
  <test name="Testing the Google">   
        <classes>         
        <class name="com.google.UI">  
     </class></classes>  
  </test>   
  <test name="Testing the Gmail">   
    <classes>         
        <class name="com.google.gmail">  
     </class></classes>  
  </test>   
</parameter></parameter></suite>  

Below I have listed some of the error messages we get when we do some mistake in the above TestNG XML file .

1.If two tests are having the same name then we see the below error
Ex :
<test name="Testing the Google">
<classes>
<class name="com.google.UI"/>
</classes>
</test>
<test name=" Testing the Google ">
<classes>
<class name="com.google.gmail"/>
</classes>
</test>

Two tests in the same suite cannot have the same name: <>
at org.testng.TestNG.checkTestNames(TestNG.java:981)
at org.testng.TestNG.sanityCheck(TestNG.java:970)
at org.testng.TestNG.run(TestNG.java:1002)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)


2.If the testname is not enclosed in double quotes("") then we will see below error
Ex : <test name=Testing the Google>
The value of attribute "name" associated with an element type "null" must not contain the '<' character. at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173) Caused by: org.xml.sax.SAXParseException: The value of attribute "name" associated with an element type "null" must not contain the '<' character. atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) 3.If the class name doesnt end with "/" character then we will see below error
org.testng.TestNGException: org.xml.sax.SAXParseException: The end-tag for element type "class" must end with a '>' delimiter.
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: The end-tag for element type "class" must end with a '>' delimiter.


4. If there is no space between parameter name and value fields then we will see below error
Ex : <parameter name="googleURL"value="http://google.com"/>

org.testng.TestNGException: org.xml.sax.SAXParseException: Element type "parameter" must be followed by either attribute specifications, ">" or "/>".
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: Element type "parameter" must be followed by either attribute specifications, ">" or "/>".


5.If the parameter attribute doesnt end with "/" character then we will see below error
Ex : <parameter name="googleURL"value="http://google.com">
org.testng.TestNGException: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".


6. If the two parameters have the same name and value attributes then we will see below error
Ex : <parameter name="googleURL"value="http://google.com"/>

org.testng.TestNGException: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".


7.Make sure there are no spaces between "/" and ">".If there are any spaces then we will see below error
Ex : <parameter name="googleURL"value="http://google.com"/ >
org.testng.TestNGException: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".

No comments:

Post a Comment