黄瓜中的替代参数类型

问题描述

我有以下黄瓜步骤,我想对它进行第一,第二,第三...等项目的测试。

When user makes a request for the 1st item

这是它的实现

@When("user makes a request for the {int}st/nd/rd/th item")

似乎正确,但是测试无法运行,并且出现错误Parameter types cannot be alternative: ... 怎么了?

解决方法

替代方案由空格分隔,因此参数与替代方案牢固地绑定在一起。因此,它期望{int}stndrdth

您将必须使用正则表达式。例如:

^user makes a request for the (\d+)(?:st|nd|rd|th) item$