如何在soapUI中登录响应中声明值? [英] How to assert value in login response in soapUI?

查看:108
本文介绍了如何在soapUI中登录响应中声明值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录请求,我想从响应中断言一个值。



这是这个回应:

 < 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>
<响应> {timestamp:2015-11-30T17:05:37Z,data:{file:null,token:16e5fd,endpoints:[{ label:app1,branc:[{url:/app1/v1.0/,name:test,}]}},success:true}<响应>
< / item>
< / login_resp>
< / soap:Body>
< / soap:Envelope>

现在我想断言:

  file = null 
endpoints = [{label:app1,branc:[{url:/app1/v1.0/,name :test,}]

我试过这个:

  //检查响应中的RequestId元素
def holder = new XmlHolder(messageExchange.responseContentAsXml)
assert holder [// ns1:file ]!= null

我无法解析类 XmlHolder

解决方案

这里是groovy脚本,它将记录配置文件,端点

  import com.eviware.soapui.support.XmlHolder 
import net.sf.json.groovy.JsonSlurper
def soapResponse = '''
< 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 并获得令牌 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.profi le
log.info json.data.endpoints


I have a login request and I want to assert a value from the response.

Here is this response:

<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>

Now I want to assert:

file = null
endpoints = [{"label": "app1", "branc": [{"url": "/app1/v1.0/", "name": "test", }]

I tried this:

// check for RequestId element in response
def holder = new XmlHolder( messageExchange.responseContentAsXml )
assert holder["//ns1:file"] != null

I have not been able to resolve class XmlHolder.

解决方案

Here is the groovy script, which will log the profile, endpoints

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

Similarly, you may query using . and json property any value as shown above.

For ex, to get timestamp - you may use -json.timestamp and to get token, json.data.token etc.,

EDIT: Based comments - intended to use in script assertion to handle response dynamically.

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.endpoints

这篇关于如何在soapUI中登录响应中声明值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆