根据SoapUI中的子值获取父值

时间:2017-03-22 01:49:59

标签: json rest groovy soapui

在响应Json中,获取所示项目的数组列表。

1 个答案:

答案 0 :(得分:1)

您在问题中看到的不是xml,而是json字符串。因此,xpath不起作用。

对于您的请求测试步骤,您可以添加Script Assertion,如下所示:

//Check the response
assert context.response, 'Response is empty or null'

//Expected subscription id, change it if needed
def expectedSubscriptionId = '2c92c0f95ae1445b015af2320235689f'

def parsedJson = new groovy.json.JsonSlurper().parseText(json)
def ids = [] as Set
parsedJson.each { item ->
   item.amendments.each { amendment ->
      if (amendment.subscriptionId == expectedSubscriptionId ) {
         ids << item.id
      }
   }
}


assert ids.size(), "id's are not found in the response for matching subscription"
log.info "Matching id's are : ${ids}"

您可以快速在线试用 Demo