2015-10-20 74 views
0

我有一个REST服务,它使用SoapUI进行测试。在我的TestSuite的第一步返回以下响应(JSON):如何将JSON值从REST POST响应传输到SOAPUI中的REST获取请求

{ 
    "mtMessageId": 52003685, 
    "status":  
    { 
    "value": 0, 
    "code": "OK", 
    "text": "Text message submitted" 
    }, 
    "custMessageId": 123, 
    "custMessageRef": null 
} 

我想“转移”的值从mtMessageId到HTTP GET在下一步请求。

请求的格式,如“/ SMS /(编号)”

怎样的价值转移到请求?

回答

1

首先,您必须在请求中使用属性设置您的get方法的资源,例如使用/SMS/${#TestCase#id}以便从第一个请求中检索它。

enter image description here

添加您的请求之间的groovy script一步步测试。使用以下代码从第一个请求的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()) 

注意,您可以用财产转移步步测试,以从您的请求中的值,并将其设置为一个属性,但是因为SOAPUI将所有为xml我更喜欢使用groovy script工作JSON。

希望它有帮助,