Selenium:多个Test Suite文件

时间:2015-12-15 15:31:56

标签: maven selenium jenkins

我正在尝试使用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>

我的主人/完整回归套件文件

回归-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>

我知道造成这个问题的原因,但我不知道如何解决这个问题。感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

错误说:

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文件(第一,第二,第三和回归套件xmls)并再次执行脚本。

修改

如果所有测试套件的格式都很好,您可以更新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>

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

答案 1 :(得分:0)

对我而言,这似乎是一个问题,因为XML文件编码为UTF-16,需要BOM字节标记(不可见字符),但标记丢失了?我猜想如果你确保testng.xml是一个UTF-8文件,问题就会消失。

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

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