armygrad
11 months agoContributor
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.