【问题标题】:Protractor-CucumberJS - Map Multiple Gherkin Statements to a Single Step FunctionProtractor-CucumberJS - 将多个 Gherkin 语句映射到单步函数
【发布时间】:2016-07-28 13:01:03
【问题描述】:

可以为多个 given-when-then 语句映射一个公共阶跃函数吗?在 Cucumber JS 中,步骤定义的格式为

this.Given(/^I have the following for a particular test$/, function () {
        //code for the step
    });

在 C# 版本的 BDD (Specflow) 中,可以将多个 gherkin 语句绑定到单个方法。例如

[Given(@"I have the following for a particular test")]
[Given(@"I have also the following for another test")]
public void GivenIHaveTheFollowingForAParticularTest()
{

}

在 CucumberJS 中是否也有任何机制来实现这一点?

【问题讨论】:

    标签: protractor bdd gherkin cucumberjs


    【解决方案1】:

    是的,你可以在 cucumber.js 中使用正则表达式来做到这一点。例如:

    this.Given(/^I have (?:the following for a particular|also the following for another)? test&/, function () {
        // code for step
    });
    

    上面的正则表达式将匹配这两个语句,因此将为这两个语句调用此步骤定义。

    要测试它,请看这里:http://www.regextester.com/?fam=95418

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-12
      • 2016-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多