Forum Discussion

xworker's avatar
xworker
Occasional Contributor
11 years ago

Go thru and insert values in each node for a request

Hi

I want to go thru a request with groovy and insert a parameter for each node in the request the has a value. The substring part is to get rid of the namespace part, not so pretty, maybe there is a better way?

This is my script so far. Works but do not update the request in soapui:




import com.eviware.soapui.support.GroovyUtils;
import com.eviware.soapui.support.XmlHolder
import groovy.util.XmlParser;


def testStep = testRunner.testCase.getTestStepAt(1)
def testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( testStepContext )

def requestHolder = testStep.testRequest.getRequestContent()
def holder = groovyUtils.getXmlHolder(requestHolder)
def rootNode = new XmlParser().parseText(holder.getXml())

rootNode.depthFirst().each {

def name

if(it.text()!="")
{
name= it.name().toString()
name=name.substring(name.indexOf("}")+1, name.length())

holder["//tec:"+name]="\${#TestCase#" +name+"}"
holder.updateProperty()

}
}

testStepContext.requestContent = holder.xml



Thx