2

I think I am copying the answer from here, but I still cannot get optional parameters to work. The two steps run independently, I just wanted to try and combine them.

Scenario:

Then(~/^set timeout(?: at (\d+) (min|hr))?$/) { int duration , String units ->

Works for

And set timeout at 30 min

But not for:

And set timeout

Which throws this error

groovy.lang.MissingMethodException: No signature of method: CucumberTestSteps$_run_closure56.doCall() is applicable for argument types: (null, null) values: [null, null] Possible solutions: doCall(int, java.lang.String), findAll(), findAll()

I've tried several other random locations for '?:' and '?' with no luck. Also several web searches which all come back to that syntax should work.

Cucumber recognizes it as a valid test because when I add

Then(~/^set timeout$/)

It recognises it as a duplicate step

cucumber.runtime.AmbiguousStepDefinitionsException: ✽.Then set timeout(test.feature:57) matches more than one step definition: ^set timeout$ in CucumberTestSteps.groovy:1128 ^set timeout(?: at (\d+) (min|hr))?$ in CucumberTestSteps.groovy:1148

MikeF
  • 764
  • 9
  • 26

1 Answers1

2

I know I'm too late for this answer, but I had the same issue today and was able to resolve it. Hopefully, this answer will help those looking for the solution to this problem. Apparently, in case of optional parameters, it passes null values to the parameters.

The problem happens because your method has an int instead of Integer. In my case, I changed the int to Integer and did a null check before proceeding. That solved the issue.