【问题标题】:Selenium: Multiple Test Suite filesSelenium:多个测试套件文件
【发布时间】:2015-12-15 15:31:55
【问题描述】:

我正在尝试使用 Maven 在 Jenkins 上运行多个 Selenium 套件文件。

我的第一个套件文件:

<suite
   name="First Automation Testing" parallel="tests"
    thread-count="20">
    <test name="First Test Case" preserve-order="true">
        <classes>
            <class
                name="com.mystore.automation.tests.FirstTest" />
           </classes>
    </test>
</suite>

第二组曲文件:

<suite
   name="Second Automation Testing" parallel="tests"
    thread-count="20">
    <test name="Second Test Case" preserve-order="true">
        <classes>
            <class
                name="com.mystore.automation.tests.SecondTest" />
           </classes>
    </test>
</suite>

第三组曲文件:

<suite
   name="Third Automation Testing" parallel="tests"
    thread-count="20">
    <test name="Third Test Case" preserve-order="true">
        <classes>
            <class
                name="com.mystore.automation.tests.ThirdTest" />
           </classes>
    </test>
</suite>

还有我的主/完全回归套件文件

回归套件.xml

<suite name="MyAutomation Testing for Checkout" parallel="tests" thread-count="20">
        <suite-files>
        <suite-file path="First-Suite.xml" />
        <suite-file path="Second-Suite.xml" />
        <suite-file path="Third-Suite.xml" />           
    </suite-files>
</suite>

现在,当我执行 maven 命令运行自动化测试 Regression-Suite.xml 时,出现以下错误:

mvn clean integration-test -Dtest.suite=Regression-Suite.xml

SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
java.lang.reflect.UndeclaredThrowableException
    at com.sun.proxy.$Proxy0.invoke(Unknown Source)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
    ... 4 more
Caused by: org.testng.TestNGException: org.xml.sax.SAXParseException; lineNumber: 50; columnNumber: 11; The markup in the document following the root element must be well-formed.
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:341)
    at org.testng.TestNG.run(TestNG.java:1030)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:122)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:88)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:104)
    ... 9 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 50; columnNumber: 11; The markup in the document following the root element must be well-formed.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$TrailingMiscDriver.next(XMLDocumentScannerImpl.java:1395)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
    at org.testng.xml.XMLParser.parse(XMLParser.java:39)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
    at org.testng.xml.Parser.parse(Parser.java:168)
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
    ... 13 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 44.203s
[INFO] Finished at: Tue Dec 15 06:04:41 PST 2015
[INFO] Final Memory: 39M/691M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "qa-builds" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.8.1:test (integration-test) on project ASAnalyticsTests: There are test failures

.

最终解决的回归套件是:

<suite-files>
<suite
   name="First Automation Testing" parallel="tests"
    thread-count="20">
    <test name="First Test Case" preserve-order="true">
        <classes>
            <class
                name="com.mystore.automation.tests.FirstTest" />
           </classes>
    </test>
</suite>
    **<!-- This is the issue the xml here is mal-formed>**
    <test name="Second Test Case" preserve-order="true">
        <classes>
            <class
                name="com.mystore.automation.tests.SecondTest" />
           </classes>
    </test>
    <test name="Third Test Case" preserve-order="true">
        <classes>
            <class
                name="com.mystore.automation.tests.ThirdTest" />
           </classes>
    </test>
</suite-files>

我知道是什么导致了这个问题,但我不知道如何解决它,感谢任何帮助。

【问题讨论】:

    标签: maven selenium jenkins


    【解决方案1】:

    错误提示:

    The markup in the document following the root element must be well-formed.
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:341)
    

    尝试在在线验证器http://www.xmlvalidation.com/ 中验证所有 testng xml 文件(第一、第二、第三和回归套件 xml),然后再次执行脚本。

    编辑:

    如果一切都是正确的,每个测试套件都格式正确,您能否更新 maven surefire 条目,如下所示:

    <plugin>
       <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
          <suiteXmlFiles>
             <suiteXmlFile>src/test/resources/first-suite.xml</suiteXmlFile>
             <suiteXmlFile>src/test/resources/second-suite.xml</suiteXmlFile>
             <suiteXmlFile>src/test/resources/third-suite.xml</suiteXmlFile>
          </suiteXmlFiles>
       </configuration>
    </plugin>
    

    另请参阅确保插件文档以根据您的需要配置测试运行:http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

    【讨论】:

    • 我不这么认为,原因是如果我单独执行测试套件(第一、第二和第三),测试会成功运行。问题是当您运行尝试 Regression-suite.xml 文件时。
    • 请发布你的 pom 文件 sn-p of surefire 插件
    • 好的,我的 pom.xml 中没有针对 maven-surefire-plugin 的测试套件的任何条目。相反,我在运行命令“mvn clean integration-test -Dtest.suite=Regression-Suite.xml”时给出了它,原因是我不希望在 pom.xml 中硬编码条目,这样我就可以执行不同的测试通过作为参数“-Dtest.suite”传入的套件
    • @Shivakumar,了解您的意图。仍然发布 pom 文件 sn-p 可能会有所帮助
    【解决方案2】:

    对我来说,这看起来像是一个将 XML 文件编码为 UTF-16 的问题,它需要 BOM 字节标记(一个不可见字符),但缺少标记?我猜如果您确保 testng.xml 是 UTF-8 文件,问题应该会消失。

    另外,您可以尝试将其放在 testng.xml 文件的顶部:

    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
    

    【讨论】:

    • 您好,所有的 xml 文件都是 UTF-8,我尝试在每个 xml 文件中添加 doctype 标头,但仍然没有运气!
    • @Shivakumar - 您确实注意到您在问题中发布的 XML 中的错误吧?格式好像不对。您错误地使用了 suite-files 标签:它仅适用于“外部加载”的 suite.xml 文件。
    猜你喜欢
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多