【问题标题】:Update soap request (node value and attribute value) using groovy使用groovy更新soap请求(节点值和属性值)
【发布时间】:2017-07-21 10:38:30
【问题描述】:

我尝试使用 groovy 更新肥皂消息。节点值可以使用以下脚本更新。有人帮我更新属性值。

XML:

<TITLE>Computer Parts</TITLE>
<PART Price="High">
   <ITEM>Motherboard</ITEM>
   <MANUFACTURER>ASUS</MANUFACTURER>
   <MODEL>P3B-F</MODEL>
   <COST> 123.00</COST>
</PART>

更新节点 xpath = //*:PART/*:COST/

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "SOAP_MSG#Request" )

holder.setNodeValue( xpath, "200" )

holder.updateProperty()

更新属性 xpath = //*:PART/@Price

如何更新价格属性?

【问题讨论】:

  • 请检查解决方案,看看是否有帮助。

标签: groovy soapui


【解决方案1】:

这是脚本,并找到内联的 cmets:

//Pass xml string to parseText method
def pxml = new XmlSlurper().parseText(xml)

//Have the expected new cost
def expectedCost = 200.00

//Have the expected new price
def expectedPrice = 'Low'

//Get the cost node
def cost = pxml.'**'.find{it.name() == 'COST'}

//Replace the value with expected value
cost.replaceBody(expectedCost)

//Get the cost node
def part = pxml.'**'.find{it.name() == 'PART'}

//Replace the value with expected value
part.@Price = expectedPrice

//Print the updated xml; use log.info if using in soapui
println groovy.xml.XmlUtil.serialize(pxml)

在线Demo

【讨论】:

    猜你喜欢
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-11
    相关资源
    最近更新 更多