【发布时间】:2017-02-10 18:44:56
【问题描述】:
我的目标
我正在尝试为大型应用程序创建功能和步骤定义的可扩展结构,我的第一个尝试是尝试将 step_definition 文件链接到功能,以便我可以对不同的步骤定义使用相同的步骤模式。
我的代码
我展示我当前的例子:
我的文件夹结构:
/features/sample.feature
/features/example.feature
/features/step_definitions/sample_steps.js
/features/step_definitions/example_steps.js
/features/step_definitions/common/common_steps.js
在我的sample.feature 我有:
Scenario: Launching Cucumber
Given I have some step definitions
When I check some step definition with parameter "any"
Then I should see all green "sample"
在我的example.feature 我有:
Scenario: Launching Cucumber
Given I have some step definitions
When I check some step definition with parameter "any"
Then I should see all green "example"
Given 和 When 步骤在 /common/common_steps.js 文件中定义并且工作正常。
Then 步骤同时定义为 sample_steps.js 和 example_steps.js,但不同。
在我的 sample_steps.js 我有:
Then('I should see all green {stringInDoubleQuotes}', (arg) => {
if (arg !== 'sample') {
throw 'I should see all green when the argument is "sample"';
}
return;
});
最后,在我的 example_steps.js 中,我有:
Then('I should see all green {stringInDoubleQuotes}', (arg) => {
if (arg !== 'example') {
throw 'I should see all green when the argument is "example"';
}
return;
});
错误
我的主要目标是在这里全部变绿,但是当然,它不起作用,我得到了这个明显的错误:
Multiple step definitions match:
I should see all green {stringInDoubleQuotes} - features\step_definitions\example_steps.js:6
I should see all green {stringInDoubleQuotes} - features\step_definitions\sample_steps.js:6
黄瓜-JVM
我知道在 cucumber-jvm 中我们可以指定一个链接特性和 step_definitions 的glue 属性,这正是我正在寻找的,但是在 cucumber-js 中。 Java 中的示例:
@RunWith(Cucumber.class)
@Cucumber.Options( glue = { "com.app.stepdefinitions.common", "com.app.stepdefinitions.sample" } )
public class SampleFeature{
}
@RunWith(Cucumber.class)
@Cucumber.Options( glue = { "com.app.stepdefinitions.common", "com.app.stepdefinitions.example" } )
public class ExampleFeature{
}
终于
如何使用 cucumber-js 实现与 cucumbr-jvm 相同的功能?
【问题讨论】:
标签: javascript bdd cucumberjs