Variable Transmission between Scenarios

Since each step in Cucumber is independent and isolated from each other, how to pass variables between steps? For example, the results obtained in the previous step need to be verified in the next step. What should we do? Compared to the use of global variables, Cucumber actually recommends another method. Here is a concept about World object, each *Hook and scene * Maintains a World object (similar to the document object in HTML or the global object in NodeJS) for saving variables, functions, etc. in the scene.

Therefore, it is very simple to use the World object to transfer variables between steps. In the step, assign the variable that needs to be passed to the World object, and then take out the value in other steps in the same scene.

And in all step definitions, you can use the this keyword to directly access the World object.

Chinese version click here.

results matching ""

    No results matching ""