Get all Nodes Names and values from a test case Response
Hello @All,
i am trying to retrieve Node names and values from a SOAP response received by a webservice's method that I test.
Here is my code and I attach the output as a file:
import groovy.util.XmlSlurper;
import groovy.util.slurpersupport.*;
// create groovyUtils and XmlHolder for response of the request
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def requestResponse = groovyUtils.expand('${CheckSdcAuthorisation[8.2]#Response}');
def holder = groovyUtils.getXmlHolder(requestResponse);
def parseResponse = new XmlSlurper().parseText(requestResponse);
def allNodeValues = holder.getNodeValues("//*");
// loop item nodes in response message
for( item in allNodeValues){
log.info "Item : [$item]"
}
The issue is that I'm not able to get node names and corresponding values. I do not understand why the for loop does not return Node values as expected? Also what code should I change to replace Item by the name of the node?
Do you have any suggestion to solve my issue?
This is going to require some groovy scripting, without a doubt. There's a feature that you can use in groovy to directly compare two xml statements called XMLUnit. You can see some of the specifics of it here and here.
Here's a snippet of code that'll compare XML:
import org.custommonkey.xmlunit.*;
XMLUnit.setIgnoreWhitespace(true)
XMLUnit.setIgnoreComments(true)
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(false)
XMLUnit.setNormalizeWhitespace(true)
def request1Xml = context.expand( '${Request1#Response}' )
def request2Xml = context.expand( '${Request2#Response}' )
Diff diff = new Diff (request1Xml, request2Xml);
DetailedDiff myDiff = new DetailedDiff (diff);
log.info(myDiff);This will give a relatively detailed difference between the two XML responses. That might give you what you want.