Cucumber Runner class throws unsecured http url TestNGException, however my .feature files and testng.xml will run the suite without issues

huangapple go评论71阅读模式
英文:

Cucumber Runner class throws unsecured http url TestNGException, however my .feature files and testng.xml will run the suite without issues

问题

当我使用我的TestRunner类(其中包含@CucumberOptions、glue和tags的类)运行黄瓜测试套件时,我会遇到以下错误:

org.testng.TestNGException:
默认情况下,TestNG禁止从不安全的URL加载DTD。如果您需要显式从http url加载DTD,请使用JVM参数[-Dtestng.dtd.http=true]
	at org.testng.xml.TestNGContentHandler.resolveEntity(TestNGContentHandler.java:115)
	at java.xml/com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(EntityResolverWrapper.java:111)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(XMLEntityManager.java:1025)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1142)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1040)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:943)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:541)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:324)
	at java.xml/javax.xml.parsers.SAXParser.parse(SAXParser.java:197)
	at org.testng.xml.XMLParser.parse(XMLParser.java:39)
	at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16)
	at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9)
	at org.testng.xml.Parser.parse(Parser.java:162)
	at org.testng.xml.Parser.parse(Parser.java:248)
	at org.testng.TestNG.parseSuite(TestNG.java:322)
	at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:374)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:39)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)

进程退出,退出码为-1

然而,当我使用.feature文件或者我的testng.xml文件运行测试时,没有任何问题,测试套件按预期运行。我的问题是,我希望与他人共享此套件,而不需要他们在VM选项中手动添加JVM参数。

这是我pom.xml文件中与maven编译器和surefire插件有关的部分:

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <systemPropertyVariables>
                    <testng.dtd.http>true</testng.dtd.http>
                </systemPropertyVariables>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

正如您所见,我已经在surefire插件下设置了systemPropertyVariable,这应该已解决http错误。这是我的Runner类的样子:

import io.cucumber.testng.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;

@CucumberOptions(
        features = { "src/test/java/Features" },
        glue = { "StepDefinitions" },
        tags = "@First or @Middle or @Last"
)

public class TestRunner extends AbstractTestNGCucumberTests {

如有帮助,将不胜感激。

英文:

When I run my cucumber test suite using my TestRunner class (the class where my @CucumberOptions, glue and tags are located) I get this error:

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]
	at org.testng.xml.TestNGContentHandler.resolveEntity(TestNGContentHandler.java:115)
	at java.xml/com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(EntityResolverWrapper.java:111)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(XMLEntityManager.java:1025)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1142)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1040)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:943)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:541)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:324)
	at java.xml/javax.xml.parsers.SAXParser.parse(SAXParser.java:197)
	at org.testng.xml.XMLParser.parse(XMLParser.java:39)
	at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16)
	at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9)
	at org.testng.xml.Parser.parse(Parser.java:162)
	at org.testng.xml.Parser.parse(Parser.java:248)
	at org.testng.TestNG.parseSuite(TestNG.java:322)
	at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:374)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:39)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)

Process finished with exit code -1

However, when I run the tests using the .feature files or my testng.xml file there are no issues and the test suite runs as expected. My issue is that I would like to share this suite with others without them having to manually add the JVM argument in their VM Options.

This is what my pom.xml looks like where the maven compiler and surefire plugin are concerned:

&lt;properties&gt;
    &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
    &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
&lt;/properties&gt;

        &lt;build&gt;
            &lt;plugins&gt;
                &lt;plugin&gt;
                    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                    &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                    &lt;version&gt;3.8.1&lt;/version&gt;
                    &lt;configuration&gt;
                        &lt;source&gt;1.8&lt;/source&gt;
                        &lt;target&gt;1.8&lt;/target&gt;
                    &lt;/configuration&gt;
                &lt;/plugin&gt;
                &lt;plugin&gt;
                    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                    &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                    &lt;version&gt;3.0.0-M5&lt;/version&gt;
                    &lt;configuration&gt;
                        &lt;systemPropertyVariables&gt;
                            &lt;testng.dtd.http&gt;true&lt;/testng.dtd.http&gt;
                        &lt;/systemPropertyVariables&gt;
                        &lt;suiteXmlFiles&gt;
                            &lt;suiteXmlFile&gt;testng.xml&lt;/suiteXmlFile&gt;
                        &lt;/suiteXmlFiles&gt;
                    &lt;/configuration&gt;
                &lt;/plugin&gt;
            &lt;/plugins&gt;
        &lt;/build&gt;

As you can see I have also already set the systemPropertyVariable under the surefire plugin which should have resolved the http error. Here is what my Runner class looks like:

import io.cucumber.testng.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;

@CucumberOptions(
        features = { &quot;src/test/java/Features&quot; },
        glue = { &quot;StepDefinitions&quot; },
        tags = &quot;@First or @Middle or @Last&quot;
)

public class TestRunner extends AbstractTestNGCucumberTests {

Any help would be greatly appreciated.

答案1

得分: 1

通常情况下,这会在您指定了XML模式配置以使用命名空间实现某些功能时发生。

之前,一些组织的命名空间URI为http,而不是https。

为相同的模式找到一个替代的https URI。

例如:
<xs:schema xmlns:xs="https://www.w3.org/2001/XMLSchema">

英文:

Usually, this happens when you have xml schema configuration specified to implement some features using the namespaces.

Earlier, some of the organization had namespaces uri with http instead of https.

Find an alternative uri for the same schema in https.

For instance:-
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

huangapple
  • 本文由 发表于 2020年9月29日 21:48:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/64120999.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定