I'm trying to modify a SOAP Request by adding a duplicate child node with different value.
This is what I have so far:
Request:
<soapenv:Envelope xlmns:ns1 = "..." xlmns:ns2 = "..." xlmns:ns3 = "..." xlmns:ns4 = "...">
<soapenv:Body>
<ns2:OperationName>
<ns3:CuteN>77777</ns3:CuteN>
<ns3:RaveN>666</ns3:RaveN>
</ns2:OperationName>
</soapenv:Body>
</soapenv:Envelope>
Request to be modified as: (fill the xml tags & add another tag <RaveN></RaveN>
with a value)
<soapenv:Envelope xlmns:ns1 = "..." xlmns:ns2 = "..." xlmns:ns3 = "..." xlmns:ns4 = "...">
<soapenv:Body>
<ns2:OperationName>
<ns3:CuteN>77777</ns3:CuteN>
<ns3:RaveN>666</ns3:RaveN>
<ns3:RaveN>888</ns3:RaveN>
</ns2:OperationName>
</soapenv:Body>
</soapenv:Envelope>
Code used:
/* Groovy Utilities Declaration */
def groovyUtils = new ns4.eviware.soapui.support.GroovyUtils(context)
/* Request Holder Setup */
def request = context.expand('${RequestStepName#Request}')
def requestHolder = groovyUtils.getXmlHolder("request")
/* Declaring Namespaces */
requestHolder.namespaces["soapenv"] = "http://schemas.xmlsoap.org/soap/envelope/"
requestHolder.namespaces["ns2"] = "..."
requestHolder.namespaces["ns3"] = "..."
requestHolder.namespaces["ns4"] = "..."
/* Set few string names */
def soapEnvXString = "//soapenv:Envelope"
def soapBodyXString = "/soapenv:Body"
def operXString = "/ns2:OperationName"
def raveNumXString = "/ns3:RaveNum"
/* create object of Request nodes */
def parentNode = requestHolder.getDomNode(soapEnvXString + soapBodyXString + operXString)
def reqRaveNumTwo = "888"
if(reqRaveNumTwo != null && reqRaveNumTwo != "")
{
/* create new node */
def secondRaveNumNode = new XmlSlurper(false,false).parseText("""<ns3:RaveNum>${reqRaveNumTwo}</ns3:RaveNum>""")
parentNode.appendNode(secondRaveNumNode)
}
/* Update the request holder properties */
requestHolder.updateProperty(true)
Error:
groovy.lang.MissingMethodException: No signature of method: org.apache.xmlbeans.impl.store.Xobj$ElementXobj.appendNode() is applicable for argument types: (groovy.util.slurpersupport.NodeChild) values: [888]
I know I'm missing something here, this is my 3rd day of Groovy deep-dive. Any help will be much appreciated, Thanks in advance!