在 Cucumber 中,如何在步骤定义中使用 {int} 时解决"Was unable to find step for"错误?



我正在使用Visual Studio代码为WebdriverIO构建一个Cucumber框架。

我有一个步骤定义,上面写着:

Then("there are/is {int} {string} displayed", (elementCount, element) => {
expect(BasePage.getElementCount(BasePage.getElement(element))).toBe(elementCount);
});

然后在我的功能文件中,我有以下场景:

Background: There have been 2 new products added to the site
Given I have created a "Product Name" via the API
And I have created a "Product Name" via the API
And I have gone to the "Products" page
And the "Product Name" is not displayed
Scenario: User searches for the product
When I set the "Search Field" to "Product Name"
Then there are 2 "Product Name" displayed

然而,我在Then步骤下面得到了一条随机的黄色波浪线("包含强调的项目"(,上面写着:

Was unable to find step for "Then there are 2 "Product Name" displayed" cucumberautocomplete

没有使用{int}参数的所有其他步骤定义都很好,整个功能文件仍然可以正确执行(即使有歪歪扭扭的线(,但从视觉上看,我希望;包含强调项目";从包含{int}的步骤定义中消失的错误。

我不确定这是VS Code、WDIO还是VS Code Cucumber扩展的问题。

wdio.conf.js文件中的黄瓜选项如下:

// If you are using Cucumber you need to specify the location of your step definitions.
cucumberOpts: {
// <string[]> (file/dir) require files before executing features
require: [`./wdio/steps/**/*.steps.js`],
// <boolean> show full backtrace for errors
backtrace: false,
// <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
requireModule: [`@babel/register`],
// <boolean> invoke formatters without executing steps
dryRun: false,
// <boolean> abort the run on first failure
failFast: false,
// <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable)
format: [`pretty`],
// <boolean> hide step definition snippets for pending steps
snippets: true,
// <boolean> hide source uris
source: true,
// <string[]> (name) specify the profile to use
profile: [],
// <boolean> fail if there are any undefined or pending steps
strict: false,
// <string> (expression) only execute the features or scenarios with tags matching the expression
tagExpression: `not @skip`,
// <number> timeout for step definitions
timeout: 60000,
// <boolean> Enable this config to treat undefined definitions as warnings.
ignoreUndefinedDefinitions: false
},

我的settings.json文件中的黄瓜自动完成设置如下:

{
"cucumberautocomplete.steps": ["./wdio/steps/**/*.steps.js"],
"cucumberautocomplete.syncfeatures": "./wdio/features/**/*.feature",
"cucumberautocomplete.strictGherkinCompletion": true,
"cucumberautocomplete.strictGherkinValidation": true,
"cucumberautocomplete.smartSnippets": true,
"cucumberautocomplete.stepsInvariants": true,
"cucumberautocomplete.skipDocStringsFormat": true,
"cucumberautocomplete.formatConfOverride": {
"And": 3,
"But": "relative"
},
"cucumberautocomplete.onTypeFormat": true,
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": true
},
"cucumberautocomplete.gherkinDefinitionPart": "(Given|When|Then)\("
}

非常感谢。

经过进一步调查,该解决方案实际上并没有执行步骤

答案:在步骤定义中将are/is替换为(are|is)。[信用@rioV8]

调查:

如果有人想知道为什么这些歪歪扭扭的线条一开始就出现了,我在下面完成了一个简短的调查。

结论:

如果步骤定义包含{string},则在定义{string}之前,不能使用/

为了支持这一点,以下是错误的步骤定义,这些定义导致了黄色的波浪线:

步骤定义:

Then("the apple/banana is {string} string today", (string) => {
return string;
});
Then("the apple/banana is {string} string and {string} string today", (string1, string2) => {
return string1 + string2;
});
Then("the apple/banana is {string} string and {int} int today", (string, int) => {
return string + int;
});
Then("the apple/banana is {int} int and {string} string today", (int, string) => {
return int + string;
});
Then("the {int} int apple/banana is {string} string today", (int, string) => {
return int + string;
});

功能步骤:

Then the apple is "fruit" string today
Then the apple is "fruit" string and "red" string today
Then the apple is "fruit" string and 1 int today
Then the apple is 1 int and "fruit" string today
Then the 1 int apple is "fruit" string today

注意:所有这些步骤定义都是通过将apple/banana更改为(apple|banana)来解决的。

相关内容

最新更新