SoapUI correlation (property transfer)

1.2k Views Asked by At

I have a REST request that respond with the following:

{
   "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlQwWE8xNnAtMmZzMWxremV5",
   "expires_in": 2592000,
   "token_type": "Bearer"
}

I want to take the value of access_token, store it in a property and reuse it for two subsequent requests.

Following some tutorial here, when running the request that obtains the access_token I get a:

error parsing target property: error unexpected element CDATA

But why?

There is no CDATA in my raw response.

1

There are 1 best solutions below

0
On BEST ANSWER

If you've problems using transfer properties step to get the JSON value from your response, you can use a groovy test step to achieve your goal.

So create a groovy test step to parse your response, get your value and set it as a property (for example at testCase level) with the follow code:

import groovy.json.JsonSlurper

// get response using the name of your test step
def response = context.expand('${REST Test Request#Response}')
// parse response
def jsonResp = new JsonSlurper().parseText(response)
// get the token an set as a property in the testCase
testRunner.testCase.setPropertyValue('access_token',jsonResp.access_token)

Then in the other testSteps (REST or SOAP...) you can use the follow code to get the access_token value you set in the testCase:

${#TestCase#access_token}

Hope this helps,