webdriverio-boneyard / wdio-cucumber-framework

A WebdriverIO v4 plugin. Adapter for Cucumber testing framework.
MIT License
77 stars 61 forks source link

No way to overload step definitions to expect a data table or not #109

Closed osmolyar closed 6 years ago

osmolyar commented 6 years ago

It appears that with wdio-cucumber-framework, it is not possible to create overloaded step definitions, such that one step definition expects a 'table' argument, and one does not.

Eg, we cannot for example define a step to use only default input options vs. one that takes data from a table as seen below. If both of the below steps are defined, a runtime error saying the step definitions are ambiguous occurs.

Instead, I would expect it to be able to resolve to the correct step definition depending on whether a data table is present following the step in the feature file.

`When(/^I create a user:$/, function () { options.login = GenericUtilities.addTimestamp(options.login); context.editUserPage=context.usersPage.createNewUser(options,context.userValidationOptions); });

vs.

When(/^I create a user:$/, function (table) { var myData=table.rowsHash(); options=context.userBusinessOptions=myData; if(options.login != '') { options.login = GenericUtilities.addTimestamp(options.login); } context.editUserPage=context.usersPage.createNewUser(options,context.userValidationOptions); }); `

BorisOsipov commented 6 years ago

The matching is done on the regular expression only, without any reference to the number of arguments that the step definition method take.

It is not a bug in wdio-cucumber-framework. You may ask in cucumber-js repo for additional explanation.