首页 > 解决方案 > 如何从詹金斯运行单个测试用例

问题描述

我在 testng 套件中有 10 个测试用例,我需要从 jenkinks 执行单个或单个测试用例,谁能帮我解决如何从 jenkins 执行单个测试用例,我尝试了 maven surfire 命令 mvn -Dtest=TestCircle test include test 命令进入 golas 并执行但它不起作用,请参考数据并纠正我如何在 jenkins 中设置目标以执行单个测试用例。“mvn clean compile install -DPICK_CONFIGURATION_FROM="JENKINS" -DEXECUTION_MODE="Remote" -Dtest=TestCircle#EAConsoleLandingPageTest test -DPLATFORM="WEB" -DOPERATING_SYSTEM="WINDOWS" -DBROWSER="chrome" -DCOMPUTERNAME="Test" -DTEST_ENVIRONMENT ="RUNFC" -DPLAN_ID="" -DTEST_TYPE="烟雾" -DGRID_URL="http://localhost:4444/wd/hub""

下面是示例测试套件: 类>

        <class
            name="com.ea.automation.tests.EAConsoleLandingPageTest">
            <methods>
                <include name="clickOnGetStartedBtn" />
                <include name="selectProjectFromLandingPage" />
                <include name="clickOnEAConsoleIcon" />
                <include name="verifyRequestProjectAccess" />
                <include name="verifyProjectAccess" />
                <include name="verifyHomePageRedierecting" />
            </methods>
        </class>
        <class
            name="com.ea.automation.tests.EAConsoleSelfServiceTest">
            <methods>
                <include name="clickOnCreateNewproject" />
                <include name="verifyProjectUserAcess" />
                <include name="switchProjects" />
                <include name="clickOnProjectSettings" />
            </methods>
        </class>
        <class
            name="com.ea.automation.tests.EAConsoleNotificationAppTest">
            <methods>
                <include name="selectProject" />
                <include name="clickOnNotification" />
                <include name="checkAllWdgetNotifications" />
            </methods>
        </class>
        <class
            name="com.ea.automation.tests.EAConsoleSupportAppTest">
            <methods>
                <include name="clickOnSupportApp" />
                <include name="checkCreateTicket" />
                <include name="clickOnCloseErrorMessageModel" />
                <include name="clickOnSupportFromApp" />
                <include name="clickOnSupportEmail" />
            </methods>
        </class>
        <class
            name="com.ea.automation.tests.EAConsoleSDKDownloadsAppTest">
            <methods>
                <include name="selectProject" />
                <include name="clickOnSDKDownloads" />
            </methods>
        </class>

标签: seleniumjenkins

解决方案


我建议的方法并不可取。因为运行 Jenkins 的唯一目的是运行一套测试用例,而不是单独的。但是您可以通过以下方式实现您的想法。

  1. 向 Jenkins 作业添加三个字符串参数。第一个参数指向testng xml文件名,第二个参数指向类名,第三个参数指向测试名。
  2. 在您的项目存储库中创建并拥有另一个 testng.xml 文件。将此文件重命名为 small.xml
  3. 所以第一个Build参数应该是small.xml
  4. Jenkins 能够在 Maven 构建开始之前执行 shell 脚本。
  5. 因此,我们将在 shell 脚本中获取我们用作 Jenkins 构建参数的参数,以修改 small.xml 文件并修改 pom.xml 文件以指向 small.xml。
  6. shell 脚本中的sed命令将有助于替换 pom.xml 和 small.xml 文件中的现有文本。你可以在互联网上搜索这个。

我在我从事的一个项目中实现了这种方法,用于根据 Jenkins 构建参数选择不同的套件文件。这种方法有效。因此在运行时,根据您传递的 Jenkins 构建参数,相应的测试将由 Jenkins 运行。


推荐阅读