Search code examples
cucumberpuppeteercucumberjs

Cucumber Puppeteer: error trying to call step function with arguments


Below is code where I try to include arguments in a Then statement (last line) when I am calling a step function I get an error message stating invalid third argument. So how do I pass parameters to the function?

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'));

Solution

  • The key is that the parameters are created in the cucumber feature file by putting the values in quotes like this: I confirm "Test Sheet 1" created in the "Revenue" folder

    Then in the step you enter placeholders like this:

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

    and finally the function looks like this:

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

    The first string becames the sheet name, and the second the Folder.