如何通过pom.xml将参数传递给testng.xml从jenkins运行单个测试用例

问题描述 投票:0回答:1

我想根据从jenkins传递的变量来运行测试用例,就像我从jenkins中选择TestCaseForHistoryPage一样,它应该只运行。

我的testng,xml看起来像:

<test name="TestCaseForInlineRedemption">
      <classes>
        <class name="test_cases.TestCaseForInlineRedemption">
      </class>
    </classes>
  </test> <!-- Test -->
  <test name="TestCaseForHistoryPage">
      <classes>
        <class name="test_cases.TestCaseForHistoryPage">
      </class>
    </classes>
  </test>


And pom like:

<plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>

      </plugin>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
            <configuration>
             <systemPropertyVariables>
             <testnames>${Dtest}</testnames>
            <country>${Dcountry}</country>
            <environment>${Denvironment}</environment>
          </systemPropertyVariables>
                    <testFailureIgnore>true</testFailureIgnore>
                <suiteXmlFiles>
                <!-- TestNG suite XML files -->             
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>                
                 <systemProperties>
            <property>          

             **<test>${Dtest}</test>** 
          </property>
         </systemProperties> 
            </configuration>
    </plugin>

我想通过pom将$ {Dtest}从jenkins传递给testng。

有人可以帮忙吗?

maven selenium jenkins testng pom.xml
1个回答
1
投票

选项1:

您可以检查此插件以运行选定的测试用例。 qazxsw poi

选项2:

为TestCaseForHistoryPage的测试用例创建另一个HistoryPage.xml文件。如下所述,在'maven-surefire-plugin'中使用动态xml文件名。

Tests Selector Plugin

现在你可以通过maven来运行它

    <configuration>

            <suiteXmlFiles>

                <!-- TestNG suite XML files -->
             <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>

            </suiteXmlFiles>


    </configuration>

在Jenkins中,您可以使用“使用参数构建”选项创建作业并创建字符串参数。现在您可以在Jenkins中传递此参数。

© www.soinside.com 2019 - 2024. All rights reserved.