我是肥皂UI中Groovy脚本的新手。我正在尝试在 Groovy 中检索响应并将内容作为字符串获取并从响应正文中获取trans id
并使用它来在 request2 中进行设置。
下面是响应正文。
{"trans response" : {
"status" : "pending request",
"trans id " : 1000078
}
}
以下代码片段提取 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)
然后,可以在后续步骤中使用 transId
属性