Forum Discussion

HaroldR's avatar
HaroldR
Contributor
8 years ago

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....
  • groovyguy's avatar
    groovyguy
    8 years ago

    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.