1

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?

paul
  • 4,333
  • 16
  • 71
  • 144

2 Answers2

0

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.

Niklas
  • 384
  • 1
  • 7
0

This is not applicable method in cucumber. There is so much issues opened and closed about your question in cucumber's github issues page.

As a work around solution I can suggest following methods. When you use (.*), you don't have to provide any arguments just erase the 'string' part while you calling step definition :

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

}

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

}
sayhan
  • 1,168
  • 1
  • 16
  • 22