默认情况下,TestNG禁用从不安全的Urls加载DTD [英] TestNG by default disables loading DTD from unsecure Urls

查看:88
本文介绍了默认情况下,TestNG禁用从不安全的Urls加载DTD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用testng maven和selenium来运行测试,目前我有以下testng.xml文件

看起来问题出在& listeners和& classes行,如果我将这些行替换为我在引用文件中拥有的xml内容,它就可以正常运行.我在以前的项目中使用过它,但效果很好,不确定为什么会出现此错误.

 <?xml版本="1.0"编码="UTF-8"?><!DOCTYPE套件系统"http://testng.org/testng-1.0.dtd" [<!ENTITY侦听器系统"listeners.xml"><!ENTITY类SYSTEM"classes.xml">]>< suite name =本地执行" verbose ="5">& listeners;< test name ="Core Integration Tests"超时="800000"><组>< run>< include name =失败"/></run></groups>& classs;</test></suite> 

Listener.xml内容就像

 < listeners>< listener class-name ="com.myclass.Listeners.TestListener"/></侦听器> 

class文件是

 < classes>< class name ="com.orders.tc_class1"/>< class name ="com.orders.tc_class2"/></classes> 

这是我遇到的错误的一部分

  org.testng.TestNGException:默认情况下,TestNG禁用从不安全的Urls加载DTD.如果需要从http URL显式加载DTD,请使用JVM参数[-Dtestng.dtd.http = true]进行加载.在org.testng.xml.TestNGContentHandler.resolveEntity(TestNGContentHandler.java:102) 

解决方案

是的,这是TestNG的默认行为,我已通过该pull请求将其引入,以修复错误

如果上述方法在模板级别上不起作用,则会对其进行修复,这是

  Run->编辑配置->模板->ng 

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)

解决方案

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

这篇关于默认情况下,TestNG禁用从不安全的Urls加载DTD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆