我们可以在同一个pom.xml文件中执行多个配置文件吗

时间:2020-05-28 04:41:00

标签: maven profiling

我已经在Eclipse中创建了一个Maven项目,并且其中有2个xml文件。我在Maven项目的pom.xml文件中创建了2个配置文件“ TestNG.xml”和“ TestNG2.xml”。 我从命令提示符处运行了以下命令 -mvn测试

预期的行为:应该执行TestNG.xml和TestNG2.xml文件下的TC。 实际行为:仅执行TestNG2.xml文件下的TC。

注意:-当我使用以下命令分别执行.xml文件时,它工作正常{TestNG.xml文件已在pom.xml文件中配置为回归} -mvn测试-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>

1 个答案:

答案 0 :(得分:1)

如果您仅两次定义surefire插件,则这些定义将相互覆盖。

相反,您需要在插件声明中定义<execution>并将其绑定到阶段。插件在<executions>块中可以有多个执行。