2

I've read numerous posts in Stackoverflow around similar issues but most of them related to steps from a scenario, not a scenario outline. My problem is that although Intellij generates the step definition stub for me, it doesn't recognise the step (when the step contains a variable) and the step it defines does not look correct for a scenario outline. If I can demonstrate with an example: This cucumber step:

enter image description here

generates the following step definition: enter image description here

The two problems here are that the feature step retains the beige background which indicates it's step is undefined and when you hover over it, the popup tooltip confirms this. Secondly, the step definition code does not have a variable passed to it, representing the options in my scenario outline. I would have expected the code generated to have been my edited code shown below, but that isn't recognised as the step definition either. enter image description here I've tried creating two similar steps but changing the name for the actual values in my scenario outline example but that doesn't work and I don't have the Substeps plugin installed. All my single scenario generated steps are recognised as soon as they are generated but the problem is specifically with scenario outlines. The Given step from a scenario outline is recognised, or any step without a variable. I've spent a week searching around online to try and find a resolution but there are very few scenario outline examples. I've done a similar exercise using Visual Studio and the SpecFlow plugin and that was a breeze.

John J Smith
  • 11,435
  • 9
  • 53
  • 72
  • Is it possible to attach sample project example? Step is resolved fine after generation on my machine. – y.bedrov Feb 11 '19 at 13:42
  • It's not really possible to attach a project example (I'd need to obfuscate so much). Could you show your example of the gherkin step and your corresponding step definition, so that I can see where the differences might be? – John J Smith Feb 12 '19 at 10:53

1 Answers1

3

After more testing on a single step in a scenario outline, I have found a solution - substitute your 'variable' with (.*) so following the example above, the recognised step definition code is:

When("the user clicks the (.*) link", (String link) -> {
        // Do some test stuff here.
    });

This doesn't appear to follow the Cucumber step definition expressions which apparently link the cucumber step to the step definition (see here). I would have expected a {String} as the expression. Also, its not what is automatically generated by Intellij's Alt + Enter.

It is quite powerful though, in so far as any cucumber step which follows the 'the user clicks the "any text here" link' will see this step definition.

John J Smith
  • 11,435
  • 9
  • 53
  • 72
  • If you use `(.*)`, you are using the "old" regular expression instead of the "new" [cucumber expression](https://docs.cucumber.io/cucumber/cucumber-expressions/) - introduced in v3.x. Does you stepdef also work with `{string}` instead of `(.*)? – Marit Mar 11 '19 at 13:08