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



我想根据从詹金斯传递的变量来运行测试用例,就像我从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>

我想通过$ {dtest}从詹金斯通过pom testng。

有人可以为此提供帮助吗?

option-1:

您可以检查此插件以运行选定的测试柜。测试选择器插件

选项2:

为TestCaseForhistoryPage的测试用例创建另一个historypage.xml文件。如下所述,请在" maven-surefire-plugin"中使用动态XML文件名。

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

    </configuration>

现在您可以通过Maven

UTILLILE将其运行
mvn clean test -Dsurefire.suiteXmlFiles=fileName.xml

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

最新更新