Selenium maven 运行不了 testng.xml 怎么回事

Tony · 2018年03月27日 · 最后由 Anson 回复于 2020年11月11日 · 1949 次阅读

maven 的 pom.xml 是这样的

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>demo</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.9.1</version>
    </dependency> 
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.2</version>
        <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
        <plugins>
            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>2.20.1</version>
                 <configuration>
                     <suitexmlfiles>
                         <suitexmlfile>testng.xml</suitexmlfile>
                     </suitexmlfiles>
                </configuration> 
            </plugin>

            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-compiler-plugin</artifactId>  
                <configuration>  
                    <encoding>UTF-8</encoding>  
                </configuration>  
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
</project>

testng.xml 是这样,放在根目录下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test thread-count="5" name="Test">
    <classes>
      <class name="demo.Sample"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

然而我运行 mvn test 的时候什么都没有运行,好像是 maven 没有找到 testng.xml, 实在不清楚怎么回事,求解答

共收到 8 条回复 时间 点赞

maven surefire

<!--添加插件 关联testNg.xml-->
 <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.5</version>
     <configuration>
         <!-- 有疑问 加上这段代码就没有多余的report文件了-->
         <!-- 添加插件,添加ReportNg的监听器生成TestNg的报告 -->
         <properties>
             <property>
                 <name>usedefaultlisteners</name>
                 <value>false</value>
             </property>
             <property>
                 <name>listener</name>
                 <value>org.uncommons.reportng.HTMLReporter</value>
             </property>
         </properties>
         <testFailureIgnore>false</testFailureIgnore>
         <suiteXmlFiles>/
             <!--<file>${project.basedir}/target/classes/testNGJunit.xml</file>-->
             <file>${project.basedir}/target/classes/testNG.xml</file>
         </suiteXmlFiles>
         <workingDirectory>target/</workingDirectory>
     </configuration>
 </plugin>
Tony #2 · 2018年04月04日 Author
oly 回复

试过了还是不管用

maven 只识别以 Test,或者 TestCase 结尾的 java 文件,试试看

楼主这个问题解决了么??

遇到同样的问题,楼主求解

默默 回复

解决了没

问题解决了!不要在 pom.xml 里指定 suiteXmlFile,不起作用。在 mvn test 后指定-Dsurefire.suiteXmlFiles=jenkins.xml 即可

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册