如何在groovy中使用context.expand获取子节点?
How to get child node using context.expand in groovy?
各位!
使用 SoapUI 5.2.1 和 Groovy
TestCase 有 2 个测试步骤:
- SOAP 请求"create"
- Groovy 脚本
请求内:
<soapenv:Envelope ... >
<soapenv:Header/>
<soapenv:Body>
<ban:transactions>
<session>x</session>
<type>y</type>
</ban:transactions>
</soapenv:Body>
</soapenv:Envelope ... >
内部脚本:
def xml = context.expand('${create#request#//ban:transactions}')
这个脚本returns:
<ban:transactions>
<session>x</session>
<type>y</type>
</ban:transactions>
我应该在脚本中更改什么,以便脚本可以 return 我:
<session>x</session>
<type>y</type>
假设你的XML是,我们将提取节点body下的数据
<Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<hello>oye1</hello>
<ok>test</ok>
<hello>oye2</hello>
<ok>test2</ok>
</Body>
</Envelope>
下面的 groovy 代码可以从提及其上方节点的 xml 中提取节点。所以在这里我们试图提取标签
下的节点
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder("testStepName#Response")
def responseXml=holder.getXmlObject()
String xmlObj=responseXml.toString()
String [] responseXmlObj=xmlObj.split('<Body>')[1].split('</Body>')
log.info responseXmlObj[0]
输出结果为
Thu Nov 23 12:38:05 GMT+05:30 2017:INFO:
<hello>oye1</hello>
<ok>test</ok>
<hello>oye2</hello>
<ok>test2</ok>
您需要将 testStepName 更改为具有响应的步骤的名称
各位!
使用 SoapUI 5.2.1 和 Groovy TestCase 有 2 个测试步骤:
- SOAP 请求"create"
- Groovy 脚本
请求内:
<soapenv:Envelope ... >
<soapenv:Header/>
<soapenv:Body>
<ban:transactions>
<session>x</session>
<type>y</type>
</ban:transactions>
</soapenv:Body>
</soapenv:Envelope ... >
内部脚本:
def xml = context.expand('${create#request#//ban:transactions}')
这个脚本returns:
<ban:transactions>
<session>x</session>
<type>y</type>
</ban:transactions>
我应该在脚本中更改什么,以便脚本可以 return 我:
<session>x</session>
<type>y</type>
假设你的XML是,我们将提取节点body下的数据
<Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<hello>oye1</hello>
<ok>test</ok>
<hello>oye2</hello>
<ok>test2</ok>
</Body>
</Envelope>
下面的 groovy 代码可以从提及其上方节点的 xml 中提取节点。所以在这里我们试图提取标签
下的节点def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder("testStepName#Response")
def responseXml=holder.getXmlObject()
String xmlObj=responseXml.toString()
String [] responseXmlObj=xmlObj.split('<Body>')[1].split('</Body>')
log.info responseXmlObj[0]
输出结果为
Thu Nov 23 12:38:05 GMT+05:30 2017:INFO:
<hello>oye1</hello>
<ok>test</ok>
<hello>oye2</hello>
<ok>test2</ok>
您需要将 testStepName 更改为具有响应的步骤的名称