Forum Discussion

armygrad's avatar
armygrad
Contributor
3 months ago

Getting info from json response into a groovy script

Hi All

 

I have a test step from a data source, which sends a request and returns a json response.

my groovy script

import groovy.json.*

// Use Get Data to get the values from the datasource and response.
def datasourceDiaryRequest = context.expand( '${Data Source#Branch}' );

// This isn't valid, just an example....
//def responseForename = context.expand( '${Get Customer by ID - REST Requestt#Response#declare error message}' 
def request = context.expand( '${REST Response#Request}' )

//Assert values in the request against values in the response
assert parsedJson.info.BranchCode.toString() 

boolean check = "FAIL";  // Initiaise our check variable

if (datasourceDiaryRequest.contains("BranchCode") ) {
	check = "PASS";
}

return check;

BranchCode is what i am trying to get to validate, so correct branch code pass, incorrect branch code fail.

The error

Any help greatly appreciated.

2 Replies

  • New Question how do i get to print out the data in each of the objects returned.

     

    • nmrao's avatar
      nmrao
      Champion Level 3

      It would be good to have separate questions. Would please create new post for the second question?