cucumber-api icon indicating copy to clipboard operation
cucumber-api copied to clipboard

passing variable between scenarios

Open jagarcad opened this issue 7 years ago • 2 comments

HI,

I am using your tool to test a rest API and needs to pass variable from one scenario to another.

In the first one I do a POST request to create an item and in second scenario later on I try to delete the created item. For that I use you grab fuction in the first scenarion and try to use it in the second but does not seem to work. It seems the scope of a variable is a scenario. Do you have a work around to pass variables ?

I tried to group everything into one scenario but got errors message on headers.

And I send a POST request to "http://192.168.99.100:5252/data/application" Then the response status should be "200" And I grab "$.application.id" as "id" Then I send a DELETE request to "http://192.168.99.100:5252/data/application/{id}"

Error 401

Unauthorized (401)

doing the same request on a different scenario work. The headers are declare by: Given I send "x-www-form-urlencoded" and accept JSON And I add Headers: | Cache-Control | no-cache | |authorization | Basic XXXXXXXXX |

Thanks for your help

jagarcad avatar Aug 20 '18 12:08 jagarcad

If you do more than one HTTP request in a scenario, any headers you set on the first request are not inherited in subsequent requests. This is why you are getting a 401 when you make the DELETE request. You need to set the Authorization header again.

biggianteye avatar Aug 20 '18 21:08 biggianteye

thanks for you reply.

I will do it that way I guess. It would be great if could use the background steps information in any request we do later on. Right now we can only use it for the first request of a scenario which is really great by the way.

Thanks for your help, I like you tool, makes life easier :)

jagarcad avatar Aug 21 '18 06:08 jagarcad