我尝试使用context.expand从响应中获取响应和特定内容,
def response = context.expand( '${Ranks of documents with SSE hits reflects scores#Response}' )
我还需要从响应中获取具体细节,比如响应是否有一系列排名:
"ranks":[2234, 1234]
如何获得两个等级值?
答案 0 :(得分:0)
您可以使用groovy脚本testStep中的JsonSlurper
,假设您获得了以下JSON:
{"ranks":[2234, 1234]}
来自您的代码:
def response = context.expand( '${Ranks of documents with SSE hits reflects scores#Response}')
您可以使用以下JsonSlurper
来获得"排名"值:
import groovy.json.JsonSlurper
// here I use this JSON as example, but you can
// parse directly your response which you get with context.expand
def response = '{"ranks":[2234, 1234]}'
def jsonRoot = new JsonSlurper().parseText(response)
log.info jsonRoot.ranks[0]
log.info jsonRoot.ranks[1]
希望这有帮助,
答案 1 :(得分:0)
在内部,SoapUI会将几乎任何内容转换为XML。您可以使用${step_name#ResponseAsXml}
获取该节点,然后根据需要解析它。类似的东西:
def ranksString = context.expand( '${Ranks of documents with SSE hits reflects scores#ResponseAsXml#//*:ranks}' )
def ranksArray = ranksString.split(",").trim()
log.info ranksArray[0]
log.info ranksArray[1]