Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a step from another step in Cucumber-JVM

In Cucumber (the ruby version) you can easily call steps from other steps and thus build hierarchical libraries of steps making it easy to write the Gherkin feature specifications in the most generic terms.

However it is not readily apparent how to do this in Cucumber-JVM and I have been unable to find documentation for it.

Let me be clear I am not interested in calling the step implementation function directly because I don't want to have to know what its signature is, nor to change the call every time the implementation changes.

Rather, I want to pass an arbitrary string that will go through the regex matcher and automatically find the matching step and execute it. Just as the engine runs all steps.

simple example of what I would expect syntax to look like to define synonym "logout":

When("user logs out") { () =>
  d.executeScript("logout();")
}
When("logout") { () =>
  Step("user logs out")
}
like image 567
Eric Hartford Avatar asked Mar 27 '14 18:03

Eric Hartford


People also ask

How do you link a feature file with step definition in Cucumber?

You have to convert your project to Cucumber project. Right-click on your project from the Project Explorer > Configure > Convert as Cucumber Project.


1 Answers

This functionality is not supported in Cucumber-JVM. (Note that the Cucumber Backgrounder document you link in your question describes using Steps within Steps as "an anti-pattern")

Essentially, we believe that Cucumber is a collaboration tool and that Gherkin is not a programming language.

You can see a longer discussion of how we arrived at this decision here

like image 142
Seb Rose Avatar answered Sep 21 '22 13:09

Seb Rose