cucumber - 如何在另一个功能文件之后运行一个功能文件?
问题描述
我有 2 个功能文件,即userstoryteacher1.feature
和userstoryteacher2.feature
. 基本上userstoryteacher1.feature
有它有 2 个标签@Dev
和@QA
.
我想以下列方式运行功能文件:-
如果我在 Cucumber 类中通过
@Dev
,@tagteacher
那么它应该选择开发 url 来打开带有凭据的页面。如果我在 Cucumber 类中通过
@QA
,@tagteacher
那么它应该选择 qa url 来打开带有凭据的页面。import org.junit.runner.RunWith; import com.optum.synergy.common.ui.controller.WebController; import cucumber.api.CucumberOptions; import cucumber.api.SnippetType; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions( plugin = { "json:target/test_results/cucumber.json"}, features = { "src/main/resources/ui/features" }, tags ={"@Dev,@tagteacher"}, snippets = SnippetType.CAMELCASE ) public class CucumberRunnerTest { public static void tearDown(){ WebController.closeDeviceDriver(); } } --------------------------------------------------------------------------- userstoryteacher1.feature file :- @TestStory Feature: Teachers timesheet need to be filled I want to use this template for my feature file Background: Scenario Outline: Open Webpage Given User Open teacher application with given <ENDPOINT> And Login into application with given <USERNAME> and <PASSWORD> And User clicks on teacher submission link @DEV Examples: | endpoint | USERNAME | PASSWORD | | http://teachersheetdev.ggn.com | sdrdev| aknewdev| @QA Examples: | endpoint | USERNAME | PASSWORD | | http://teachersheetqa.ggn.com | sdrqa | aknewdev| ----------------------------------------------------------------------------- userstoryteacher2.feature file :- Feature : I'm at the teachers page @tagteacher Scenario: Open app home page and click the button Given I'm at the teachersheet homepage When User clicks Add Task button Then User should see the tasks schedule
解决方案
Cucumber 的设计使您无法将场景或功能文件链接在一起。每个场景都应该从一开始就作为一个独立的“测试”运行。
使用功能文件进行编程是一种可怕的反模式。而是将编程向下推到步骤定义层,或者更好地推到步骤定义使用的助手中。
如果你想充分利用 Cucumber,你需要用它来表达正在做什么以及为什么它很重要。从你的例子来看,这似乎都是关于教师填写他们的时间表,所以你的场景应该是这样的
Scenario: Fill in timesheet
Given I am a teacher
And I am logged in
When I fill in my timesheet
Then I should see my timesheet has been saved.
您在 Givens 中设置状态,并为您创建的每个场景构建辅助方法,以便将来的场景可以轻松设置状态。例如Given I am a teacher
可能是这样的
def 'Given I am a teacher' do
teacher = create_new_teacher;
register_teacher(teacher)
return teacher
end
这是建立在以前的情况下注册新教师的。如果您遵循此模式,您可以使用单个 Given 的简单场景,只需使用单个方法调用即可进行大量设置。这比将几个功能文件链接在一起要好得多!!
推荐阅读
- python - 等值线地图比例显示太多数字 - 即整个时间范围 - 同时显示滑块,直到滑块移动
- c# - 找不到类型或命名空间名称“应用程序”(您是否缺少 using 指令或程序集引用?) [WebApi]
- visual-studio-code - 我可以从 rust-analyzer 中删除类型注释帮助吗?
- flutter - 如何在 Flutter 上播放 GStreamer 媒体
- javascript - 如何将十进制转换为二进制?
- python - python合并排序实现错误:超出最大递归深度
- python-3.x - 优化使用 tensordot 或 einsum 创建包含矩阵的 ndarray
- c++ - 如何用符号写字母
- android - 我想在 gradle 编译 apk 期间添加一个新文件
- java - JUnit5 测试 void 方法。获取 org.opentest4j.AssertionFailedError: 预期: