Search code examples
overloadingcucumber-jvmgherkincucumber-javacucumber-serenity

same cucumber gherkin step but different methods


I have a step

Given I have a pass
  |hotel|

and

Given I have a pass

One runs with data and one runs without data. To handle above requirement I wrote two functions:

@Given("^I have a pass$")
public void givenIhaveAPass() {

}

and

@Given("^I have a pass$")
public void givenIhaveAPass(DataTable table) throws Exception {

}

but it is giving error DefinitionTestSuite.initializationError DuplicateStepDefinition Duplicate

Want to use same step with method overloading. How can I do that?


Solution

  • I don't think this is possible since the matching is done with regex only, and not considering the parameters. You can do two just

    Given I have a pass with: |hotel|

    and

    Given I have a pass

    and match them in your two java methods. This way you can give them a clearer name as well.