我在Eclipse中创建了一个Maven项目,里面有2个xml文件,我在pom.xml文件中为Maven项目创建了2个配置文件 "TestNG.xml "和 "TestNG2.xml"。我在Maven项目的pom.xml文件中创建了2个配置文件 "TestNG.xml "和 "TestNG2.xml",我在命令提示符下运行了以下命令--mvn test。
预期行为:TestNG.xml和TestNG2.xml文件下的TC都应该被执行,实际行为:只有TestNG2.xml文件下的TC被执行。
注意:- 当我使用下面的命令分别执行.xml文件时,工作正常{TestNG.xml文件在pom.xml文件中被描述为Regression}- mvn test -PRegression。
下面是我在pom.xml文件中的代码快照。
<groupId>Rohit</groupId>
<artifactId>MavenProject05202020</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MavenProject05202020</name>
<url>http://maven.apache.org</url>
<profiles>
<profile>
<id>Regression</id>
<!-- Below is MAVEN SURE FIRE PLUGIN. This will help to execute all your TCs present in your test folder{i.e.:-src/test/java}-->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<!-- Below is MAVEN SURE FIRE PLUGIN.
<profile>
<id>Smoke</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng2.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- below is the dependency for Selenium project -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<!-- Below is the dependency for TESTNG. -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<!-- Below is the dependency for RestAPITest project -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
如果你只是定义了两次surefire-plugin,这些定义会互相覆盖。
相反,你需要定义一个 <execution>
的插件声明中,并将其绑定到一个阶段。插件可以有一个以上的执行。<executions>
块。