0

I am trying to filter out the JSON response values by passing on few parameters dynamically. Below is the code.

import com.eviware.soapui.support.XmlHolder
import groovy.json.JsonSlurper

responseContent = testRunner.testCase.getTestStepByName("Request 1").getPropertyValue("Response")
jsonresponse = new JsonSlurper().parseText(responseContent)

log.info jsonresponse.context["parameter"]

context["parameter"] stores the values from an Excel sheet and doing only a log.info for context["parameter"], it shows those values correctly. Below is the output of the code log.info context["parameter"].

Thu Dec 14 07:18:53 CST 2017:INFO:firstName
Thu Dec 14 07:18:53 CST 2017:INFO:lastName
Thu Dec 14 07:18:54 CST 2017:INFO:frNum
Thu Dec 14 07:18:54 CST 2017:INFO:notes 

But when I execute the code

log.info jsonresponse.context["parameter"]

Result:

Thu Dec 14 07:20:41 CST 2017:INFO:[]

Thu Dec 14 07:20:41 CST 2017:INFO:[]

Thu Dec 14 07:20:41 CST 2017:INFO:[]

Thu Dec 14 07:20:42 CST 2017:INFO:[]

Thu Dec 14 07:20:42 CST 2017:INFO:[]

log.info jsonresponse yields the below response out of which I need to get certain values (values stored in the context["parameter"])

Thu Dec 14 07:21:45 CST 2017:INFO:[{errorMessage=null, middleName=null, lastName=Kosnick, frName=Kosnick Steven H , mplastName=null, competeRgnTxt=null, doNum=null, gddUnitStDate=null, fdNum=null, mpfirstName=null, legalEntityID=null, noNum=null, contractType=Financial Rep, frNum=046426, offcNum=NO 091, notes=Active, fullTmeSrvDt=null, firstName=Steven, networkOfficeNum=091}]

1 Answer 1

1

Instead of this :

log.info jsonresponse.context["parameter"]

Try this :

log.info jsonresponse[context["parameter"]]

This should resolve your issue :)

Sign up to request clarification or add additional context in comments.

1 Comment

Or jsonresponse."$context.parameter" should work as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.