如何将 JSON 值从 REST POST 响应传输到 SOAPUI 中的 REST 获取请求
How to Transfer a JSON value from a REST POST Response to a REST Get Request in SOAPUI
我有一个正在使用 SoapUI 测试的 REST 服务。我的 TestSuite 中的第一步 returns 以下 Response (Json):
{
"mtMessageId": 52003685,
"status":
{
"value": 0,
"code": "OK",
"text": "Text message submitted"
},
"custMessageId": 123,
"custMessageRef": null
}
我想在下一步中'Transfer'将mtMessageId 中的值放入HTTP Get 请求中。
请求的格式类似于“/SMS/{id}”
如何将值传输到请求中?
首先,您必须在请求中使用 属性 设置 get
方法的资源,例如使用 /SMS/${#TestCase#id}
以便从第一个请求中检索它。
然后在您的请求之间添加一个 groovy script
testStep。使用以下代码从第一个请求的 json 响应中获取 id
,并为第二个请求设置为 属性。
import groovy.json.*
// get the response from the first request using its name
def response = context.expand('${Request 1#Response}')
// parse it
def json = new JsonSlurper().parseText(response)
log.info json.mtMessageId
// get the json value an set it as property in testCase
context.testCase.setPropertyValue("id",json.mtMessageId.toString())
请注意,您可以使用 属性 传输 testStep 从您的请求中获取值并将其设置为 属性,但是由于 SOAPUI 将全部转换为 xml 我更喜欢使用groovy script
上班 json.
希望对您有所帮助,
我有一个正在使用 SoapUI 测试的 REST 服务。我的 TestSuite 中的第一步 returns 以下 Response (Json):
{
"mtMessageId": 52003685,
"status":
{
"value": 0,
"code": "OK",
"text": "Text message submitted"
},
"custMessageId": 123,
"custMessageRef": null
}
我想在下一步中'Transfer'将mtMessageId 中的值放入HTTP Get 请求中。
请求的格式类似于“/SMS/{id}”
如何将值传输到请求中?
首先,您必须在请求中使用 属性 设置 get
方法的资源,例如使用 /SMS/${#TestCase#id}
以便从第一个请求中检索它。
然后在您的请求之间添加一个 groovy script
testStep。使用以下代码从第一个请求的 json 响应中获取 id
,并为第二个请求设置为 属性。
import groovy.json.*
// get the response from the first request using its name
def response = context.expand('${Request 1#Response}')
// parse it
def json = new JsonSlurper().parseText(response)
log.info json.mtMessageId
// get the json value an set it as property in testCase
context.testCase.setPropertyValue("id",json.mtMessageId.toString())
请注意,您可以使用 属性 传输 testStep 从您的请求中获取值并将其设置为 属性,但是由于 SOAPUI 将全部转换为 xml 我更喜欢使用groovy script
上班 json.
希望对您有所帮助,