TestNG by default disables loading DTD from unsecure Urls

后端 未结 14 880
[愿得一人]
[愿得一人] 2021-01-02 00:10

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 &class

相关标签:
14条回答
  • 2021-01-02 00:32

    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

    0 讨论(0)
  • 2021-01-02 00:34

    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
    0 讨论(0)
  • 2021-01-02 00:34

    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):

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

    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.

    0 讨论(0)
  • 2021-01-02 00:37

    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

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

    0 讨论(0)
  • 2021-01-02 00:39

    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
    

    0 讨论(0)
  • 2021-01-02 00:40

    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>
    
    0 讨论(0)
提交回复
热议问题