TestNG by default disables loading DTD from unsecure Urls
Solution 1
Yes, that's the default behavior of TestNG and I had introduced it through that pull request to fix the bug https://github.com/cbeust/testng/issues/2022
To set the JVM arguments in intelliJ, choose Run > Edit Configurations
, and add this JVM argument in the VM options section after -ea
(which would be there by default.
For more information on editing configurations, please refer to the official documentation here
Added screenshot for easy to find in Intellij
Argument value
-ea -Dtestng.dtd.http=true
If the above does not work do at template level, this will fix it, which is
Run--> Edit configuration --> template --> testng
Solution 2
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 3
- 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 4
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 5
- If you run your project only from the eclipse/other IDE's update your TestNG preferences and add statement
-Dtestng.dtd.http=true
in 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.
Related videos on Youtube
msiles
Updated on July 05, 2022Comments
-
msiles almost 2 years
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)
-
Rahul L almost 5 yearsThis is new implementation for security github.com/cbeust/testng/pull/2023/files . As message says set JVM argument [-Dtestng.dtd.http=true]
-
msiles almost 5 yearsThanks @RahulL but how can I add that argument if I'm running the test from intellij, right click on the xml and then run
-
Rahul L almost 5 yearsAdd in VMs parameters testng.org/doc/idea.html or search
-
TeachMeJava almost 4 yearsAlso if you add maven dependency but forget to add testng.jar file as external library, same error occurs.
-
PHPGuru over 3 yearsIntelliJ is fixing this: youtrack.jetbrains.com/issue/IDEA-234765
-
-
Boss Man almost 4 yearsHow can I execute tests with no internet access? I get a
Connection Timeout
error with that arg. -
Joe Coder over 3 yearsAdd what JVM argument?
-
ochedru over 3 yearsDefinitely the best answer: fixing the template solves the issue for all test runs
-
RoyalTiger over 3 yearsThe best answer.
-
Csa77 over 3 yearsThis shouldn't be the accepted answer as it is incomplete, the other answer has the correct solution, include "-Dtestng.dtd.http=true"
-
Changgull Song over 3 yearsThank you for pointing this out -- I don't want my project's participants go through the same pain of setting up the IntelliJ testng run config and this option really helps.
-
IPlato over 3 yearsyou duplicated my answer stackoverflow.com/a/63517935/3470233
-
Prostak over 3 yearsnice! as simple as that! no sarcasm. worked for me.
-
Hola Soy Edu Feliz Navidad over 3 yearsThis iis the more appropriated answer.
-
Alissa over 3 yearsThis is so much better than making all your team add some stuff to run config. @msiles would you mind changing accepted answer to this? The other ones are more of a workaround...
-
Alissa over 3 yearsThis is a workaround anyway. The proper solution would be to change url in <DOCTYPE> to https. As per answer by @Amerousful
-
Debra Bula over 3 yearsThis worked for me today. Followed by a refresh of the file, rebuild and re-run. Thanks!
-
PDHide over 3 yearsEven creator is not sure about the fix , thanks for ths
-
anandhu about 3 yearsI add like this. When i run using the button on toolbar then it works, But if i righclick on the class file and runs, another run configuration is getting created without the argument and it runs using that one so again gets that error
-
RomanKousta about 3 yearsBut I don't have this DOCTYPE stuff in my project, and I still got this error.
-
Gaj Julije about 3 yearsThis is the solution, do not know, why no one is upvolting it.
-
Deepak about 3 yearsThank You. You saved my day with this easy approach.
-
Gooner4Life almost 3 yearsThis worked for me, this needs more upvote
-
Rashad Nasirli over 2 yearsworked on me.thanks
-
Rashad Nasirli over 2 yearsmade someone's day. Thank you