30

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)
msiles
  • 657
  • 3
  • 10
  • 19
  • 1
    This is new implementation for security https://github.com/cbeust/testng/pull/2023/files . As message says set JVM argument [-Dtestng.dtd.http=true] – Rahul L Aug 01 '19 at 09:39
  • 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 – msiles Aug 01 '19 at 13:25
  • Add in VMs parameters https://testng.org/doc/idea.html or search – Rahul L Aug 01 '19 at 13:53
  • Also if you add maven dependency but forget to add testng.jar file as external library, same error occurs. – TeachMeJava Aug 07 '20 at 09:25
  • IntelliJ is fixing this: https://youtrack.jetbrains.com/issue/IDEA-234765 – PHPGuru Nov 24 '20 at 23:37

15 Answers15

44

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

Gaurav Khurana
  • 3,423
  • 2
  • 29
  • 38
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
42

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"

Amerousful
  • 2,292
  • 1
  • 12
  • 26
13
  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.

10

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"

Satyendra Sharma
  • 1,436
  • 13
  • 19
  • 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 – anandhu Feb 17 '21 at 10:28
7
  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.

Farhaan Shaik
  • 123
  • 1
  • 2
  • 8
6

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

IQbrod
  • 2,060
  • 1
  • 6
  • 28
5

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>
IPlato
  • 191
  • 2
  • 7
  • 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. – Changgull Song Sep 18 '20 at 22:44
  • Thank You. You saved my day with this easy approach. – Deepak May 01 '21 at 08:19
3

Change "http://testng.org/testng-1.0.dtd" to "https://testng.org/testng-1.0.dtd" in your suite file.

Vishal Jagtap
  • 896
  • 11
  • 16
3

In the TestNG file change the value (http) inside the <!DOCTYPE> parameter into https as highlighted in the below image. That is it.

TestNG File

2

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:

  1. Open Eclipse and go to Window -> Preferences
  2. Expand TestNG at left-hand side and click Run/Debug
  3. At right-hand side: Type the following text in the JVM args text field: -Dtestng.dtd.http=true
  4. Click Apply and Close button enter image description here
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
1

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

enter image description here

IPlato
  • 191
  • 2
  • 7
1

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 image description here

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

1

To solve this problem in Eclipse follow following steps:

  1. Go to windows -> Preferences->TestNG->Run/Debug
  2. In JVM_args add the following -Dtestng.dtd.http=true
  3. Click on Apply and close button.
  4. Right-click on your project select Maven -> Update project
  5. 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.

0

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.

  1. I changed the arguments in TestNG Configuration as shown below (added step): Changing TestNG arguments

  2. 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.) enter image description here

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.

Demnofocus
  • 21
  • 6
0

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