Below is my code, i want to use CartItemId from scenario1 response as request for scenario2, but scenario cannot get its value.
Scenario: /api/wishlist/item/add - add to wishlist
Given path '/api/wishlist/item/add'
And headers allHeaders.HeadersToken
And request {"CultureCode":"CHS","IsSpecificSku":0,"MerchantId":"#(data.StyleMerchantId)","SkuId":"#(data.SkuId)","UserKey":"#(data.UserKey)"}
When method POST
Then status 200
* def CartItemId = response.CartItems[0].CartItemId
* print CartItemId
* print response
Scenario: /api/wishlist/item/remove - remove from wishlist
Given path '/api/wishlist/item/remove'
And headers allHeaders.HeadersToken
And request {"CartItemId":"#(CartItemId)","CultureCode":"CHS","UserKey":"#(data.UserKey)"}
When method POST
Then status 200
You are trying to test a "flow" here which is "first add, then remove". Please combine the two
Scenario
s into one.Detailed answer here: https://stackoverflow.com/a/46080568/143475