黄瓜:无法将整数值传递给步骤

Cucumber: Can't pass an integer value to a step

我有以下步骤:

When REST create 10 users prefixed with "user"

我试着定义这样的步骤:

唯一的工作步骤定义是

@When("^REST create (*) users prefixed with \"(.*)\"$")

但显然这匹配所有内容,我只想传递 1 及以上的整数。

接下来我尝试的所有操作均无效(未粘贴):

@When("^REST create (d+) users prefixed with \"(.*)\"$") 
@When("^REST create d+ users prefixed with \"(.*)\"$") 
@When("^REST create {int} users prefixed with \"(.*)\"$") 
@When("^REST create ([1-9]+[1-9]*) users prefixed with \"(.*)\"$") 
@When("^REST create [1-9]+[1-9]* users prefixed with \"(.*)\"$")

为什么???我无法理解问题!

Cucumber 版本为 1.2.5。我知道它已经过时了,但我是一个大型项目的一部分,目前我们更愿意使用这个版本。

我相信您正在寻找:

@When("^REST create (\d+) users prefixed with \"([^\"]*)\"$")
public void restCreateUsersPrefixedWith(int arg0, String arg1) {
// Write code here that turns the phrase above into concrete actions 
}

例如,如果您有场景大纲并且想为每个场景提供不同的值:

Scenario Outline: Creation of users 
When REST create "number of users" users prefixed with "user"

Examples:

| number of users |

| 10              |

| 100             |

| 1000            |

那么对应的步骤定义为:

@When("^REST create \"([^\"]*)\" users prefixed with \"([^\"]*)\"$")
public void restCreateUsersPrefixedWith(String arg0, String arg1)  {
    // Write code here that turns the phrase above into concrete actions
    }

我在我的步骤定义中有一个整数没有被粘合的相同问题。失败的步骤定义试图使用 ([^[0-9]]*) 来处理数字。但是当我将其更改为 ([0-9]) 时,它起作用了。因此,如果您将代码更改为:

@When("^REST create ([0-9]) users prefixed with \"(.*)\"$")

...应该可以解决问题。