简体   繁体   中英

Using Groovy in soapUI to extract a JSON field for use in subsequent steps

I am new to Groovy scripting in soapUI. I'm trying to retrieve response in Groovy and get the content as string and get trans id from the response body and use it to set in request2.

Below is the response body.

{"trans response" : {
   "status" : "pending request",
   "trans id " : 1000078
  }
}

The following snippet extracts the value of trans id (trailing space included) and sets a test case property:

import groovy.json.JsonSlurper

def response = new groovy.json.JsonSlurper().parseText(context.expand('${RESTRequest1#Response}'))
def String transId = response.'trans response'.'trans id '

// Set as a test case property
testRunner.testCase.setPropertyValue("transId", transId)

You can then use the transId property in subsequent step steps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM