hidroh / cucumber-api

API validator in BBD style with Cucumber
https://rubygems.org/gems/cucumber-api
Apache License 2.0
52 stars 56 forks source link

passing variable between scenarios #29

Open jagarcad opened 6 years ago

jagarcad commented 6 years ago

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

biggianteye commented 6 years ago

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.

jagarcad commented 6 years ago

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 :)