TestNG by default disables loading DTD from unsecure Urls

60,589

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

enter image description here

If the above does not work do at template level, this will fix it, which is

Run--> Edit configuration --> template --> testng

enter image description here

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

  1. Right Click on the class, select Run--> Run configuration
  2. By default one testNg class will be generated with same class name under testng option
  3. Select that class and go to Arguments tab
  4. 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-

  1. How to Edit Run Config How to Edit Run Config

  2. How to add >VM argument: "-Dtestng.dtd.http=true" How to add >VM argument: "-Dtestng.dtd.http=true"

Solution 5

  1. 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.
  2. 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.

Share:
60,589

Related videos on Youtube

msiles
Author by

msiles

Updated on July 05, 2022

Comments

  • msiles
    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
      Rahul L almost 5 years
      This is new implementation for security github.com/cbeust/testng/pull/2023/files . As message says set JVM argument [-Dtestng.dtd.http=true]
    • msiles
      msiles almost 5 years
      Thanks @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
      Rahul L almost 5 years
      Add in VMs parameters testng.org/doc/idea.html or search
    • TeachMeJava
      TeachMeJava almost 4 years
      Also if you add maven dependency but forget to add testng.jar file as external library, same error occurs.
    • PHPGuru
      PHPGuru over 3 years
      IntelliJ is fixing this: youtrack.jetbrains.com/issue/IDEA-234765
  • Boss Man
    Boss Man almost 4 years
    How can I execute tests with no internet access? I get a Connection Timeout error with that arg.
  • Joe Coder
    Joe Coder over 3 years
    Add what JVM argument?
  • ochedru
    ochedru over 3 years
    Definitely the best answer: fixing the template solves the issue for all test runs
  • RoyalTiger
    RoyalTiger over 3 years
    The best answer.
  • Csa77
    Csa77 over 3 years
    This shouldn't be the accepted answer as it is incomplete, the other answer has the correct solution, include "-Dtestng.dtd.http=true"
  • Changgull Song
    Changgull Song over 3 years
    Thank 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
    IPlato over 3 years
    you duplicated my answer stackoverflow.com/a/63517935/3470233
  • Prostak
    Prostak over 3 years
    nice! as simple as that! no sarcasm. worked for me.
  • Hola Soy Edu Feliz Navidad
    Hola Soy Edu Feliz Navidad over 3 years
    This iis the more appropriated answer.
  • Alissa
    Alissa over 3 years
    This 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
    Alissa over 3 years
    This is a workaround anyway. The proper solution would be to change url in <DOCTYPE> to https. As per answer by @Amerousful
  • Debra Bula
    Debra Bula over 3 years
    This worked for me today. Followed by a refresh of the file, rebuild and re-run. Thanks!
  • PDHide
    PDHide over 3 years
    Even creator is not sure about the fix , thanks for ths
  • anandhu
    anandhu about 3 years
    I 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
    RomanKousta about 3 years
    But I don't have this DOCTYPE stuff in my project, and I still got this error.
  • Gaj Julije
    Gaj Julije about 3 years
    This is the solution, do not know, why no one is upvolting it.
  • Deepak
    Deepak about 3 years
    Thank You. You saved my day with this easy approach.
  • Gooner4Life
    Gooner4Life almost 3 years
    This worked for me, this needs more upvote
  • Rashad Nasirli
    Rashad Nasirli over 2 years
    worked on me.thanks
  • Rashad Nasirli
    Rashad Nasirli over 2 years
    made someone's day. Thank you