'TestNG by default disables loading DTD from unsecure Urls
I'm using testng maven and selenium to run my tests, currently I have the following testng.xml file
Looks like the problem is with the &listeners and &classes lines, If I replace those lines with the xml content that I have on the referenced files it runs fine. I have used this in a previous project and it worked fine, not sure why I'm getting this error.
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" [
<!ENTITY listeners SYSTEM "listeners.xml">
<!ENTITY classes SYSTEM "classes.xml">
]>
<suite name="Local Execution" verbose="5">
&listeners;
<test name="Core Integration Tests" time-out="800000">
<groups>
<run>
<include name="failed"/>
</run>
</groups>
&classes;
</test>
</suite>
Listener.xml content is like
<listeners>
<listener class-name="com.myclass.Listeners.TestListener"/>
</listeners>
And classes file is
<classes>
<class name="com.orders.tc_class1"/>
<class name="com.orders.tc_class2"/>
</classes>
This is part of the error I'm getting
org.testng.TestNGException:
TestNG by default disables loading DTD from unsecure 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:102)
Solution 1:[1]
Just change all yours
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"
on https:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"
Solution 2:[2]
- Right Click on the class, select Run--> Run configuration
- By default one testNg class will be generated with same class name under testng option
- Select that class and go to Arguments tab
- In the VM arguments provide -Dtestng.dtd.http=true
Thats it.
Solution 3:[3]
Just to avoid confusion and make it easier for some one who is new to the Config edit option etc attaching a snap for getting it done in intellij.
So as answered by- Mr Krishnan M. : Go to Edit Config for your Cucumber TestNGRunner class, then we have to add another argument to the VM options as below-
Solution 4:[4]
- If you run your project only from the eclipse/other IDE's update your TestNG preferences and add statement
-Dtestng.dtd.http=truein JVM_args. - If you are looking for a general fix where you run maven from CLI as well then update all your TestNG.xml files
FROM
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
TO:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
I personally prefer updating the DOCTYPE.
Solution 5:[5]
Adding those VM options : -ea -Dtestng.dtd.http=true solved this problem.
But if you want to solve it for each run either for any class or method, you need to add the same in TestNG template, please refer to this screenshot.
Intelij TestNg Template SS
Solution 6:[6]
Another option, if want it work for all the tests, regardless where you run them from, set the option in the pom by setting a system property. Add the following for maven-surefire-plugin and maven-failsafe-plugin
<configuration>
<systemPropertyVariables>
<testng.dtd.http>true</testng.dtd.http>
</systemPropertyVariables>
</configuration>
Solution 7:[7]
Change "http://testng.org/testng-1.0.dtd" to "https://testng.org/testng-1.0.dtd" in your suite file.
Solution 8:[8]
In the TestNG file change the value (http) inside the <!DOCTYPE> parameter into https as highlighted in the below image. That is it.
Solution 9:[9]
Details Exception is as follows:- 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]
To fix the Exception it needs to set the JVM arguments. To set the JVM arguments in Eclipse:
Solution 10:[10]
To fix this for all tests run from IntelliJ only, can update the TestNG template with the -Dtestng.dtd.http=true vm option. Will need to delete existing test runs or manually add the vm option (I'd just remove them). All the tests run following the template change will have the mentioned vm option.
Run/Debug Configurations -> Edit Configurations -> Templates -> TestNG
Solution 11:[11]
Please follow all the steps as below. Works perfectly after configuring JVM arguments in Eclipse.
Problem Statement:
TestNG by default disables loading DTD from unsecure 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]
Often we need to use certain VM arguments on the JVM that launches the Rule Project.
To do so, the following 2 steps are needed: • Define a new installed JRE with default JVM arguments: -- Go to the Eclipse Window > preferences > Java > Installed JREs". -- Select the Default JRE and Click on Duplicate. -- Change the JRE name as per your choice, for example myJRE and Enter the Default VM arguments as “-Dtestng.dtd.http=true” enter image description here
-- Click Finish. --- Uncheck the default JRE and check the new JRE added with VM arguments. --- Click Apply, Apply and Close.
• Configure the Rule Project launch configuration to use the new installed JRE: -- Go to the Run > Run Configurations --- Run Configuration Dialog is in view.
--- Enter the Name of your choice, for example: RunConfigWithJVMArgs. --- Test tab: ? Project name by default displayed. ? Select the “Suite” option and browse for your testng.xml file present in your project folder. For example: src/main/resources/testng.xml enter image description here
--- Arguments tab: ? Enter ““-Dtestng.dtd.http=true” in the VM arguments text field. --- JRE tab: ? Select “Alternate JRE : “ as the newly added JRE with JVM arguments. --- No other changes required. --- Click Apply and then Run.
If the suite starts and runs successfully in Eclipse, then it will work when you run the packaged JAR file as well.
Note: Perform mvn clean and mvn package –Dmaven.test.skip=true after changing the above configurations in Eclipse.
Once the JAR is ready, it will have the new JRE configured with JVM arguments and it will fix the problem statement.
Solution 12:[12]
To solve this problem in Eclipse follow following steps:
- Go to windows -> Preferences->TestNG->Run/Debug
- In JVM_args add the following -Dtestng.dtd.http=true
- Click on Apply and close button.
- Right-click on your project select Maven -> Update project
- Now go to your pom.xml and click on Run as ->Maven Test
Now below problem "TestNG by default disables loading DTD from unsecure Urls" will not be there.
Solution 13:[13]
I came across this error recently and tried the solutions given above but still got the error. Setting JVM arguments is the solution for this problem anyways as shown in above answers but I added one more step and it fixed my issue.
I changed the arguments in TestNG Configuration as shown below (added step):

I also changed the arguments in LoginTests.testSuccessfullLogin. (This step would only be necessary if you have ran the program with the issue. Otherwise if you are running the program for first time, it will create this configuration with the same arguments as in TestNG configuration.)

I also noticed that if you haven't done the second step mentioned above, it will create a new configuration called LoginTests.testSuccessfullLogin(1) with the changed arguments in order to run the tests.
Solution 14:[14]
I too faced this issue. I was unable to run the test from my xml file with right click run. So, the solution that I did was change the "" in the xml file to "https://... " and it solved the issue. Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow





