【问题标题】:how to run individual test cases from jenkins by passing parameters to testng.xml through pom.xml如何通过 pom.xml 将参数传递给 testng.xml 从 jenkins 运行单个测试用例
【发布时间】:2019-07-17 06:25:05
【问题描述】:

我想根据从 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 将 jenkins 中的 ${Dtest} 传递给 testng。

有人可以帮忙吗?

【问题讨论】:

标签: maven selenium jenkins testng pom.xml


【解决方案1】:

选项一:

您可以检查此插件以运行选定的测试用例。 Tests Selector Plugin

选项 2:

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

    <configuration>

            <suiteXmlFiles>

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

            </suiteXmlFiles>


    </configuration>

现在你可以使用通过 maven 运行它

mvn clean test -Dsurefire.suiteXmlFiles=fileName.xml

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

【讨论】:

    猜你喜欢
    • 2019-06-30
    • 1970-01-01
    • 2016-06-16
    • 1970-01-01
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    相关资源
    最近更新 更多