Xml – Comparing element values of SOAP Response and JDBC response in SOAPUI using groovy

comparegroovyxml

I would like to compare the values of the elements under a node fetched from SOAP response and a JDBC Request.
I'm able to print the values with the below groovy code but failed to compare the same as I'm not very good at coding.

Note: Element names are same but in different order in both the responses.

I would like to compare the values based on the element names from both the responses irrespective of the order of the elements.
Note: Compare only if the JDBC element value is not null.

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

def JMSHolder = groovyUtils.getXmlHolder( "SOAPTestStep#Response" )
def JDBCHolder = groovyUtils.getXmlHolder( "JDBC Request step#ResponseAsXml" )

def node1 = JMSHolder.getDomNodes("//ns0:Study[1]/")
def node2 = JDBCHolder.getDomNodes("//Row[1]/
")

node1.each {
log.info it.QName.getLocalPart()
log.info it.firstChild.nodeValue
}

node2.each {
log.info it.QName.getLocalPart()
log.info it.firstChild.nodeValue
}

Best Answer

Please see this script, maybe will help you

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "Request#Request" );
def holder2 = groovyUtils.getXmlHolder("Responses#ResponseAsXml")

def stringList=[]
def stringList2=[]

for( node in holder['//name] )
{  
  stringList =stringList+node 
}


for( node2 in holder2['//name'] )
{ 
  stringList2 =stringList2+node2 
    if (node2 in stringList ) assert true
    else assert null
}


log.info "Request>" + stringList
log.info "result>"+ stringList2
Related Topic