Error: Step implementation missing for: [step_definition] with cypress & Cucumber when using Scenario outline with example

Error: Step implementation missing for: [step_definition] with cypress & Cucumber when using Scenario outline with example

我根据 Cypress.io 设置了以下 Cucumber BDD。当对值进行硬编码时测试运行良好,但在“带有示例的场景大纲”方式中给出时失败。我错过了什么?

错误:

特征文件:

步骤定义:

版本:

赛普拉斯 7.1.0: 柏树黄瓜预处理器:“^4.0.3”,

尝试所有组合后,这个(使用正则表达式)成功了。

When(/^keying the vessel identifier ([^"]*) on the search box$/, searchTerm => {
    Search.doSearch(searchTerm)
});

您正在传递它 {String},但它应该是 {string},全部小写。那应该可以解决您的问题。

When(/^keying the vessel identifier {string} on the search box$/, (vesselName) => {
    Search.doSearch(searchTerm)
});

编辑:

请改用此方法,删除正则表达式模式并使用双引号来定义 WHEN 语句。如果您使用的是正则表达式模式,那么我认为您无法使用 {string} 在您的步骤中定义字符串参数。

When("keying the vessel identifier {string} on the search box", (vesselName) => {
    Search.doSearch(searchTerm)
});

一如既往,说明在文档中。

如果您使用 Cucumber 表达式 {string},则要匹配的字符串必须用引号引起来(双引号或单引号)。

你在特征文件中的给定行应该是这样的:

When keying the vessel identifier 'something' on the search box

https://cucumber.io/docs/cucumber/cucumber-expressions/(参数类型)

{string} : Matches single-quoted or double-quoted strings, for example "banana split" or 'banana split' (but not banana split). Only the text between the quotes will be extracted. The quotes themselves are discarded. Empty pairs of quotes are valid and will be matched and passed to step code as empty strings.