Currently having an issue where the wrong step is selected when I'm trying to run my gherkin tests.
Steps
I have two And
steps for my gherkin tests:
-
shop {string} provided a shop log on {word} at UTC time {string}
-
shop {string} provided a shop log on {word}
Gherkin Test
Scenario 1
Whenever I run my gherkin tests which has the following:
And the shop "Gherkin Shop" provided a shop log on "Friday" at UTC time "01:00:00"
The selected step is the second one instead of the first one.
Scenario 2
Whereas if I have the following And
step
the shop "Gherkin Shop" provided a shop log on "Friday"
Then the only step which matches is 'shop {string} provided a shop log on {word}'
What's causing this
I went ahead and inspected the code which determines the step selection and found this located in feature_file_runner.dart
.
final executable = _steps.firstWhereOrNull(
(s) => s.expression.isMatch(step.debug.lineText),
);
Potential solution
If we use this line of code instead, we can see that in the first Gherkin test scenario there would be 2 matching results.
_steps.where((s) => s.expression.isMatch(step.debug.lineText)).toList()
If we extend the accessibility of the _expectParameterCount
variable for StepDefinitionGeneric
so there's a getter within ExecutableStep
, then we could check which step has more steps and always opt to using that step over the rest.
If they have the same number of steps, we could resort to the default behaviour of taking the first match.
Temporary solution
I can reword the step to make it more unique which is fine for now but not ideal and it'd be nicer if this improvement can be made for a future version 🤞