SoapUI Groovy提供了更方便的方法,GroovyUtils 与 XmlHolder ,具体如下:
//获取GroovyUtil
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
//获取XmlHolder
def holder = groovyUtils.getXmlHolder( "TestStep#Request" )
//def holder = groovyUtils.getXmlHolder( "TestStep#Response" )
holder.declareNamespace("com", "http://gsh/common")
//这里的命名空间需要事先指定,xmlPath中不需要带Soap包装
holder.setNodeValue( "//com:NewSub/RequestHeader/com:TransactionId", "1" );
//将请求写入TestStep
groovyUtils.setPropertyValue( "TestStep", "Request", holder.prettyXml );