Site icon TestingDocs.com

How to fix TestNG by default disables loading DTD from unsecured Urls error?

Overview

TestNG by default disables loading DTD from unsecured Urls. If you need to explicitly load the DTD from a http url, please do so by using the JVM argument [-Dtestng.dtd.http=true].

Indication of the error is failure to run the tests. Error stack trace displayed as shown below:

Error Trace

org.testng.TestNGException: 
TestNG by default disables loading DTD from unsecured Urls. 
If you need to explicitly load the DTD from a http url, please do so by
 using the JVM argument [-Dtestng.dtd.http=true]
	at org.testng.xml.TestNGContentHandler.resolveEntity
(TestNGContentHandler.java:115)
	at java.xml/com.sun.org.apache.xerces.internal
.util.EntityResolverWrapper.resolveEntity(EntityResolverWrapper.java:111)
	at java.xml/com.sun.org.apache.xerces.internal
.impl.XMLEntityManager.resolveEntityAsPerStax(XMLEntityManager.java:1025)
	at java.xml/com.sun.org.apache.xerces.internal
.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1142)
	at java.xml/com.sun.org.apache.xerces.internal
.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1040)
	at java.xml/com.sun.org.apache.xerces.internal
.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:943)
	at java.xml/com.sun.org.apache.xerces.internal
.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
	at java.xml/com.sun.org.apache.xerces.internal
.impl.XMLDocumentFragmentScannerImpl
.scanDocument(XMLDocumentFragmentScannerImpl.java:541)
	at java.xml/com.sun.org.apache.xerces.internal
.parsers.XML11Configuration.parse(XML11Configuration.java:888)
	at java.xml/com.sun.org.apache.xerces.internal
.parsers.XML11Configuration.parse(XML11Configuration.java:824)
	at java.xml/com.sun.org.apache.xerces.internal
.parsers.XMLParser.parse(XMLParser.java:141)
	at java.xml/com.sun.org.apache.xerces.internal
.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
	at java.xml/com.sun.org.apache.xerces.internal
.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
	at java.xml/com.sun.org.apache.xerces.internal
.jaxp.SAXParserImpl.parse(SAXParserImpl.java:324)
	at java.xml/javax.xml.parsers.SAXParser.parse(SAXParser.java:197)
	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:162)
	at org.testng.xml.Parser.parse(Parser.java:248)
	at org.testng.TestNG.parseSuite(TestNG.java:322)
	at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:374)
	at org.testng.TestNG.initializeEverything(TestNG.java:1017)
	at org.testng.remote.support.RemoteTestNG6_12
.initialize(RemoteTestNG6_12.java:22)
	at org.testng.remote.AbstractRemoteTestNG
.run(AbstractRemoteTestNG.java:98)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

Root Cause

The main cause for the error is that we are pointing to insecure HTTP URL locations in the testng.xml file. For example DTD

Fix

The fix is to modify the http xml prologs, DTD links to secure HTTPS. Example, change the DTD specification in the TestNG XML file:

http://testng.org/testng-1.0.dtd 

Modify this to HTTPS link:

https://testng.org/testng-1.0.dtd

Save the Test suite XML file.

Re-run the tests.

Alternatively, we can use the JVM argument hook [-Dtestng.dtd.http=true]. In the IDE

Run >> Edit configuration we can add the JVM hook.

TestNG Tutorials on this website can be found at:

https://www.testingdocs.com/testng-framework-tutorial/

For more details on the TestNG Framework, visit the official website of TestNG at:

https://testng.org

Exit mobile version