【问题标题】:Cucumber Puppeteer: error trying to call step function with argumentsCucumber Puppeteer:尝试使用参数调用 step 函数时出错
【发布时间】:2020-06-24 13:12:52
【问题描述】:

下面是我在调用步进函数时尝试在 Then 语句(最后一行)中包含参数的代码 我收到一条错误消息,指出第三个参数无效。 那么如何将参数传递给函数呢?

async function confirmSheetCreated(folderName,sheetName) {
    await this.page.waitFor(1500);
    let sheetExists=await this.sheetExists(folderName,sheetName)
    await this.page.isTrue(sheetExists);
}



When('I click plus button in top menu', { timeout: 5*1000 }, clickAddSheet);
When('I click Sheet option in dropdown', { timeout: 5*1000 }, clickSelectSheet);
When('I fill in New Sheet Lookup dialog', { timeout: 5*1000 },fillNewLookupSheetDialog);
When('I click Create New Sheet button',{ timeout: 5*1000 },clickCreateNewSheet);
Then( 'I confirm new sheet created',{ timeout: 5*1000 },  confirmSheetCreated('Revenue','Test Sheet 1'));

【问题讨论】:

  • 您将函数的结果分配为步骤定义,而不是函数本身。此外,您的步骤不会为函数产生任何参数,因此这也是一个错误。
  • 请解释我如何使用不同的参数调用confirmSheetCreated,这样我就不必使用硬编码的folderName和SheetName具有不同的功能

标签: cucumber puppeteer cucumberjs


【解决方案1】:

关键是参数是在黄瓜特征文件中通过将值放在引号中创建的,如下所示: 我确认在“收入”文件夹中创建的“测试表 1”

然后在步骤中输入这样的占位符:

    Then ('I confirm {string} created in the {string} folder,{timeout:5*1000},confirmSheetCreated);

最后函数看起来像这样:

async function confirmSheetCreated(sheetName, folderName) {
    await this.page.waitFor(1500);
    let sheetExists=await this.sheetExists(folderName,sheetName)
    await this.page.isTrue(sheetExists);
}

第一个字符串成为工作表名称,第二个字符串成为文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 2010-10-15
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    相关资源
    最近更新 更多