如何使用JavaScript正确处理与黄瓜结合的开关案例?



我正在尝试使用切换情况,以便使用JavaScript进行可重用的测试步骤。

然而,黄瓜表明我的步骤是不确定的,我不确定为什么。

所讨论的特征步骤如下:

当我搜索"people"name "characterSearch">

我的特性背后的代码如下:
When('I search for {string} with name {string}', async (type, name) => {
switch(type) {
case "planets":
await searchFormPO.planetsRadioButton.click();
break;
case "people":
await searchFormPO.peopleRadioButton.click();
break;
default:
throw 'Please use planets or people as type input for this testcase.';
}
await searchFormPO.input.click;
await searchFormPO.input.sendKeys(name);
await searchFormPO.searchBtn.click();
});

运行我的测试时显示的错误如下:

Undefined. Implement with the following snippet:
When('I search for {string}', function (string) {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});

它建议我的代码应该是一个函数,我已经尝试过了。但是我的JS技能有点生疏,所以我可能忽略了一些东西。

我试过用谷歌搜索JS中的switch cases with cucumber,但是我不能用谷歌来解决这个问题。

这段代码工作正常,问题是在错误映射的旧功能文件中。

最新更新