Migrating a Cucumber suite: what replaces the World object we keep scenario state in?
Asked 5,290 views1 answer
16votes
Our Cucumber suite keeps everything on the World: the id of the record the last step created, the current user, a couple of counters, and a response object that three later steps read.
Feature files copy across fine and the tags lint clean. The step definitions are where I am stuck, because half of them are this.something = ... and there is no this to put it on.
There is no World, and most of what you were keeping on it has a home already.
Values captured from a response become scenario variables:
gherkin
When I save the response JSON path "id" as "orderId"
And I send a GET request to "/orders/{{orderId}}"
Every {string} argument and doc string is rendered before the step runs, and the variables resolve in order: values saved in this scenario, then the current dataset row, then vars from the environment file. So the counters and the id stop being state you manage and become values you name.
The current user is not yours to track either — @user:standard or the leased-user step sets username, password, userId and role as variables, and applies the storage state.
The response object needs nothing: the assertion steps already read the last response.
What is genuinely left — a piece of object state two steps on the same page share — lives on the page object instance. pages.get(Class) caches one instance per class per scenario, so a field you set in a When is there in the Then, and it is thrown away when the scenario ends. Read variables from inside the class with this.vars and this.render().