我有一个登录请求,我想从响应中断言一个值。
以下是这样的答复:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://TUI.io/ns/20110812">
<soap:Body>
<login_resp>
<zato_env>
<cid>K07FKWJTWZMCNFJJBNDQVMZTW4TQ</cid>
<result>TUI_OK</result>
</zato_env>
<item>
<response>{"timestamp": "2015-11-30T17:05:37Z", "data": {"file": null, "token": "16e5fd", "endpoints": [{"label": "app1", "branc": [{"url": "/app1/v1.0/", "name": "test", }]}}, "success": true}</response>
</item>
</login_resp>
</soap:Body>
</soap:Envelope>现在我要断言:
file = null
endpoints = [{"label": "app1", "branc": [{"url": "/app1/v1.0/", "name": "test", }]我试过这个:
// check for RequestId element in response
def holder = new XmlHolder( messageExchange.responseContentAsXml )
assert holder["//ns1:file"] != null我无法解析类XmlHolder。
发布于 2015-12-01 18:51:56
下面是groovy脚本,它将记录配置文件、端点
import com.eviware.soapui.support.XmlHolder
import net.sf.json.groovy.JsonSlurper
def soapResponse='''
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://zato.io/ns/20130518">
<soap:Body>
<login_resp>
<zato_env>
<cid>K07FKWNDQVMZTW4JTWZMCNFJJBTQ</cid>
<result>ZATO_OK</result>
</zato_env>
<item>
<response>{"timestamp": "2015-11-30T17:05:37Z", "data": {"profile": null, "token": "1225555-sd18-4895-a037-d81ae2e273e2", "endpoints": [{"label": "app6", "branches": [{"url": "/app7/v1.0/", "name": "test", "api_version": "1.0", "label": "test"}], "appname": "app5"}, {"label": "app4", "branches": [{"url": "/gui/v1.0/", "name": "est", "api_version": "1.0", "label": "test"}], "appname": "gui"}, {"label": "app3", "branches": [{"url": "/app3/v1.0/", "name": "test", "api_version": "1.0", "label": "test"}], "appname": "app3"}, {"label": "app2", "branches": [{"url": "/app2/v1.0/", "name": "test", "api_version": "1.0", "label": "test"}], "appname": "app2"}, {"label": "app1", "branches": [{"url": "/app1/v1.0/", "name": "test", "api_version": "1.0", "label": "test"}], "appname": "app1"}]}, "success": true}</response>
</item>
</login_resp>
</soap:Body>
</soap:Envelope>
'''
def holder = new XmlHolder(soapResponse)
def response = holder.getNodeValue('//*:response')
def json = new JsonSlurper().parseText(response)
log.info json.data.profile
log.info json.data.endpoints类似地,您可以使用.和json属性进行查询,如上面所示。
对于前任,要得到timestamp -你可以使用-json.timestamp和token,json.data.token等等,
编辑:基于注释-打算在脚本断言中使用来动态处理响应。
import com.eviware.soapui.support.XmlHolder
import net.sf.json.groovy.JsonSlurper
def soapResponse = messageExchange.responseContent
def holder = new XmlHolder(soapResponse)
def response = holder.getNodeValue('//*:response')
def json = new JsonSlurper().parseText(response)
log.info json.data.profile
log.info json.data.endpointshttps://stackoverflow.com/questions/34005588
复制相似问题