【问题标题】:When launching maven, showing an error testng.xml is not valid file启动 maven 时,显示错误 testng.xml is not valid file
【发布时间】:2018-10-11 03:47:30
【问题描述】:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 数据驱动 乌迪米 0.0.1-快照

<!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
<dependencies>
    <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
    <dependency>
        <groupId>com.relevantcodes</groupId>
        <artifactId>extentreports</artifactId>
        <version>2.41.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.11.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
    <dependency>
        <groupId>org.uncommons</groupId>
        <artifactId>reportng</artifactId>
        <version>1.1.2</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>4.2.0</version>
    </dependency>



    <!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail -->
    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.6.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.6</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.17</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.17</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/dom4j/dom4j -->
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.17</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
    <dependency>
        <groupId>org.apache.xmlbeans</groupId>
        <artifactId>xmlbeans</artifactId>
        <version>2.6.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
        <scope>test</scope>
    </dependency>

     <dependency>
    <groupId>org.apache.maven.surefire</groupId>
    <artifactId>surefire-testng</artifactId>
    <version>2.18.1</version>
    </dependency>

</dependencies>
<build>
<pluginManagement>
  <plugins>
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.18.1</version>
       <configuration>
    <suiteXmlFiles>
      <suiteXmlFile>src/test/resources/runner/testng.xml</suiteXmlFile>
    </suiteXmlFiles>
  </configuration>
    </plugin>
  </plugins>
</pluginManagement>

无法在项目 Udemy 上执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test):执行目标 org.apache.maven.plugins:maven 的默认测试-surefire-plugin:2.18.1:test failed: 分叉进程出错 [错误] org.apache.maven.surefire.testset.TestSetFailedException:套件文件 E:\Udemy\Udemy\src\test\resources\runner\testng.xml 不是有效文件 [错误] 在 org.apache.maven.surefire.testng.TestNGXmlTestSuite.locateTestSets(TestNGXmlTestSuite.java:116) [错误] 在 org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:83) [错误] 在 org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) [错误] 在 org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) [错误] 在 org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) [错误] -> [帮助 1] [错误] [错误] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。 [错误] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。 [错误] [错误] 有关错误和可能的解决方案的更多信息,请阅读以下文章: [错误] [帮助1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

【问题讨论】:

    标签: selenium


    【解决方案1】:

    用这个更新你的插件

         <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <suiteXmlFiles>
                     <suiteXmlFile>src/test/resources/runner/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
    

    【讨论】:

    • 谢谢。这比上述方法好吗? Surefire 不会将测试名称记录到控制台。我应该使用侦听器还是记录器来进行日志记录?
    • 是的,您可以使用相同的侦听器,您可以创建一个实现 ITestListener 的类,您可以添加所有 Override 类,在 OnTestStart 中您可以这样做
    • @Override public void onTestStart(ITestResult result) { LOG.info("#####Test {}.{}() Started#####", result.getInstanceName(),结果.getMethod().getMethodName()); }
    • 类似地在 TestSucess @Override public void onTestSuccess(ITestResult result) { LOG.info("#####Test {}.{}() 成功完成#####", 结果。 getInstanceName(), result.getMethod().getMethodName()); }
    【解决方案2】:
     <properties>
        <testng.files.location>src/test/resources/</testng.files.location>
        <testng.file>testng.xml</testng.file>
        <maven-surefire.version>2.20</maven-surefire.version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <aspectj.version>1.8.10</aspectj.version>
        <testng.version>6.14.2</testng.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire.version}</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>${testng.files.location}${testng.file}</suiteXmlFile>
                    </suiteXmlFiles>
    
                </configuration>
            </plugin>
        </plugins>
    
    </build>
    <dependencies>
        <dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.41.1</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.11.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>3.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testng.version}</version>
        </dependency>
    </dependencies>
    

    【讨论】:

    • 我们如何设置这些变量的值? ${testng.files.location}${testng.file}
    • 你必须在我上面给出的 部分中提供 ${testng.files.location}${testng.file} 的值
    猜你喜欢
    • 2017-03-03
    • 2016-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 2019-08-03
    相关资源
    最近更新 更多