[英]Using Groovy in soapUI to extract a JSON field for use in subsequent steps
I am new to Groovy scripting in soapUI. 我是soapUI中Groovy脚本的新手。 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. 我试图在Groovy中检索响应,并以字符串形式获取内容,并从响应正文中获取
trans id
,并使用它在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: 以下代码段提取
trans id
的值(包括尾随空间)并设置测试用例属性:
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 然后,您可以在后续步骤中使用
transId
属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.