Here is the sample TestNG file :
It is also important to know about error messages.Sometimes we learn more from errors :)
I have put some of the error messages we get when we go wrong in the above TestNG XML file .
Here are the error codes we will see when we have done any error in the above XML file.
1.If two tests are having the same name then we see 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: <<Test anme>>
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 doesnot elclosed in double quotes("") then we wills ee 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"/>
<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 "/>".
Hi
ReplyDeleteI am getting SAXParseException : The value of attribute "default host" associated with an element type "null" must not contain the '<' character.
Th thing is that :
So this default host I am injecting it from a script at run time .
If I put defaulthost as localhost then I get exception below this , where I am injecting all the hosts as :
<%Virtual Host Injection%>
Although in server.xml which is generated after deployment at run time seems to getting populating with correct values , but makes me worry on seeing errors in logs
you need to replace "<" and ">" symbols with special characters .
ReplyDeleteThe below link helps you.
http://support.microsoft.com/kb/316063