Simon N
Simon N

Reputation: 337

KarateDSL Parsing a value from a response and adding to next scenario payload not working

New to Karate and I have read a load of the Karate tutorials and cannot get my head around what looks to be a trivial issue.

I have one post request that successfully lists all applications, from the response I get the ID of the first application and print it to console and it displays with no issue. However, when I come to use the applicationId in the payload for the next scenario (int he same feature file, the applicationId is not added to the payload.

Scenario: List all applications
Given path '/ListApplications'
And request {"request":{},"Session":'#(session)'}
When method POST
Then status 200
And def applicationId = response.Applications[0].Id
* print 'Hello ' + applicationId //i see the application id of 7203 here in the console log

Scenario: Get Application
Given path '/GetApplication'
And request {"request":{"ApplicationId":'#(applicationId)'},"Session":'#(session)'} 
When method POST //post here just uses string applicationId instead of 7203
Then status 200

Any help greatly appreciated

Upvotes: 1

Views: 448

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58088

You are using 2 Scenarios where you should have only one.

Please read this section of the docs: https://github.com/intuit/karate#script-structure

I think if you comment out this line it will work:

# Scenario: Get Application 

Upvotes: 1

Related Questions