Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
API for stateless step definitions #214
Currently, the only way to pass state between step definitions is by storing state as instance variables.
This is cumbersome in some languages, in particular for Java where it becomes tricky to share state between classes. DI is the only way to address this.
I would like to propose an alternative API for Step Definitions where:
This would remove the need for a World or DI. It would reduce coupling and make it more explicit what is passed between step definitions.
Once we're happy with the API we can create new issues to implement this in various Cucumbers.
(I've been thinking about this for a while, and I'm glad I am not the only one! See cucumber/cucumber-jvm#1136)
referenced this issue
May 28, 2017
I think this solution trades a coupling a between step definitions and the World/DI modules for a coupling to the order in which steps in gherkin must be written. So I don't think this can be used to completely replace the World or DI modules. In the worst case you end up passing the World between steps.
For example take a website like Gmail that personalizes your account even when you are not logged in because it recognizes that nobody else ever uses that machine.
Given I am a specific kind of customer And I have a login account that was previously used to login When use the website Then I am greeted with my name
In this scenario I'd have to pass the information about the customer (his name) from the first step all the way to last step through one or more steps that don't use the information.
But other then that yeah this can useful.
referenced this issue
Jun 10, 2017
I am very much in favour of pure functions, or better of allowing both pure and impure step definitions for languages that were FP is not the main paradigm.
I think DI framework support is still needed to inject what is not part of the scenario context into the step definition class: components from the application or shared test dependencies (e.g. Selenium). In this way we don't need to handle different scopes for context parameters, as they should always have scenario scope, but we'd be flexible.