Testng XmlSuite.getAllParameters()引发NullPointerException

时间:2018-07-20 13:59:24

标签: java testng

在运行脚本时,它会正确运行测试,但是最后,在加载XmlSuite并生成报告时,它会抛出NullPointerException。
仅供参考,
 -这是一个间歇性问题,因为有时它无法生成报告。
 -我正在使用自定义的html报告技术来生成报告。
 -6.11:这是TestNg版本,我在代码中使用。

如果您检查以下链接cbeust/testng changes,则在TestNG更新版本6.9.13中解决了类似的问题'以编程方式加载XmlSuites时出现NullPointerException'

如果您需要更多信息,请发表评论并告诉我。
错误:

  org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
    Caused by: java.lang.NullPointerException
        at org.testng.xml.XmlSuite.getAllParameters(XmlSuite.java:416)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:352)
        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
        at org.testng.TestNG.runSuites(TestNG.java:1144)
        at org.testng.TestNG.run(TestNG.java:1115)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:177)
        at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:105)
        ... 9 more

Surefire插件配置:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration><argLine>-Xmx3072m</argLine></configuration>
        <version>2.12</version>
    </plugin>

套件文件:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Prod suite" parallel="tests" thread-count="100">

<listeners>
        <listener class-name="xyz.listener.AnnotationTransformer"/>
      <listener class-name="xyz.listener.TestListener"/>
  </listeners>

    <test name="Prod - OSCAR Locale-US-Set1 Browser-chrome"
        preserve-order="true">
        <method-selectors>
            <method-selector>
                <script language="beanshell"><![CDATA[(groups.containsKey("PVT") || (groups.containsKey("PVT") && groups.containsKey("INCLUDE_US_ONLY"))) && 
                                                    !(groups.containsKey("EXCLUDE_US")) && 
                                                    !(groups.containsKey("INCLUDE_UK_ONLY")) && 
                                                    !(groups.containsKey("INCLUDE_AU_ONLY")) &&
                                                    !(groups.containsKey("INCLUDE_CN_ONLY")) && 
                                                    !(groups.containsKey("INCLUDE_JP_ONLY"))]]>
                </script>
            </method-selector>
        </method-selectors>
        <parameter name="browser" value="" />
        <parameter name="country" value="us" />
        <parameter name="language" value="en" />
        <parameter name="env" value="" />

        <classes>
            <class
                name="xyz" />
        </classes>
    </test>
</suite>
protected void generateFailureSuite(XmlSuite xmlSuite, ISuite suite, String outputDir) { 
    // XmlSuite failedSuite = (XmlSuite) xmlSuite.clone(); 
    XmlSuite failedSuite = xmlSuite.shallowCopy(); 
    // failedSuite.setName("[" + xmlSuite.getName() + "]"); 
    failedSuite.setName("Failed suite [" + xmlSuite.getName() + "]"); 
    m_xmlSuite = failedSuite; 
    if (null != failedSuite.getTests() && failedSuite.getTests().size() > 0) { 
        // create testng-failed.xml file to any dir 
    }
}

0 个答案:

没有答案