Using Groovy to insert new tag into request. Need help with insert point (XmlParser - FindAll)
- 9 years ago
Again, this isn't pretty.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = context.expand( '${SOAPRequest#Request}' )
def root = new XmlParser( false, true ).parseText( holder )fragmentToAdd = new XmlParser( false, true ).parseText( toAdd ) //Node to be added in the format <tag>Value</tag>
root.'**'.findAll() {
//The new node will be added after rootNode
if ( it.name().toString().contains( rootNode.substring(2,rootNode.length()) )) {
int nodeCount = 0
def insertPoint = it.parent().children().find {
nodeCount++// Find the node in the list of nodes
it.name().toString().contains( rootNode.substring(2,rootNode.length()))
}
it.parent().children().add( nodeCount , fragmentToAdd ) //Add new node at the specified point.
}
}
String outxml = groovy.xml.XmlUtil.serialize( root )request = testRunner.testCase.getTestStepByName( "SOAPRequest" )
request.getProperty("request").setValue( outxml )Angie