selenium - 如何从詹金斯运行单个测试用例
问题描述
我在 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>
解决方案
我建议的方法并不可取。因为运行 Jenkins 的唯一目的是运行一套测试用例,而不是单独的。但是您可以通过以下方式实现您的想法。
- 向 Jenkins 作业添加三个字符串参数。第一个参数指向testng xml文件名,第二个参数指向类名,第三个参数指向测试名。
- 在您的项目存储库中创建并拥有另一个 testng.xml 文件。将此文件重命名为 small.xml
- 所以第一个Build参数应该是small.xml
- Jenkins 能够在 Maven 构建开始之前执行 shell 脚本。
- 因此,我们将在 shell 脚本中获取我们用作 Jenkins 构建参数的参数,以修改 small.xml 文件并修改 pom.xml 文件以指向 small.xml。
- shell 脚本中的sed命令将有助于替换 pom.xml 和 small.xml 文件中的现有文本。你可以在互联网上搜索这个。
我在我从事的一个项目中实现了这种方法,用于根据 Jenkins 构建参数选择不同的套件文件。这种方法有效。因此在运行时,根据您传递的 Jenkins 构建参数,相应的测试将由 Jenkins 运行。
推荐阅读
- shell - awk - 在引号之间打印输出
- c++ - 通过引用传递指针时出错
- wordpress - 如何在模板源中找到硬编码属性的位置?
- linux - Linux内核CPU频率子系统中struct cpufreq_policy有什么用
- java - java中用于自定义文件资源管理器的布局管理器
- php - 如何使用 usort 函数比较数组中的值?
- c++ - 为什么这段代码会导致 Windows Defender 发疯,并将这段代码识别为名为 Ludicrouz.j 的木马
- http - 如何将 cookie 用于 HTML 和 API 调用具有不同域的站点?
- azure-devops - 用于部署的 yaml 管道中的条件
- c# - 是否可以在不分配返回类型的情况下调用函数