在 soapUI 中使用 Groovy 提取 JSON 字段,以便在后续步骤中使用



我是肥皂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 属性

最新更新