Forum Discussion

b_sukesh's avatar
b_sukesh
New Contributor
13 years ago

Compare two response xml's

How to compare two response XML files in Soap Ui Pro?

Regards,
Sukesh.

6 Replies

  • Jasper175's avatar
    Jasper175
    Frequent Contributor
    A very difficult but good question...
    The answer you don't want is "I don't know" exactly - I've been using SoapUI for 4 years now.

    There are a few things you could do but rather annoying.

    1. The best way in PRO is "Message Content Assertion"
    > This is rather a nice addition, but again you're stuck with PRO as well as the "assertion" rules and not exactly just eye-shot comparing.
    But This is the way I would go if you want to match EVERY return field.

    The other issue is if your response if "null" in any field is NOT returned in your element you will run into a problem.

    2. XPath Match between two testSteps
    > Same concept but you can use in free version. In your second step you can set the XPath Match and point to the previous run step.
    The issue is you're actually looking for a "MATCH" TRUE - which is most likely what you don't want.

    3. Groovy Script assertion is probably better flexibility.
    > This you can "GET DATA" on each field you want to compare.

    def xml1-firstname = context.expand( '${getCustomerInfo1#Response#declare namespace ns2=\'http://work.com/services/servicelayer\'; //ns2:GetCustomerInfoResponse[1]/ns2:regions[1]/ns2:name[1]}' )
    def xml2-firstname = context.expand( '${getCustomerInfo2#Response#declare namespace ns2=\'http://cleveland.vonage.com/services/servicelayer\'; //ns2:GetCustomerInfoResponse[1]/ns2:towns[1]/ns2:nxx[1]}' )

    xml1-firstname == xml2firstname
    or
    xml1-firstname != xml2firstname

    Again VERY tedious work and annoying because you will need a specific code parameter if you want it to == or !=

    It would be nice if SoapUI can add a XPath MisMatch
  • nmrao's avatar
    nmrao
    Champion Level 3
    Hi,

    Am using a library to compare two xml objects in groovy. The below is the link where you can get the details of the library. Please note that you need compile it, create a jar and copy it under $SOAPUI_HOME/bin/ext before starting soapui.
    http://code.google.com/p/deep-equals/

    In the groovy script create xml object for both actual and expected using XmlSlurper, you may find example at
    http://marxsoftware.blogspot.in/2009/11/slurping-xml-with-groovy.html
    DeepEquals.deepEquals(actual, expected)
    Hope this is helpful.

    Regards,
    Rao.
  • Sorry to resurrect an ancient thread, but:

    2. XPath Match between two testSteps
    > Same concept but you can use in free version. In your second step you can set the XPath Match and point to the previous run step.
    The issue is you're actually looking for a "MATCH" TRUE - which is most likely what you don't want.


    Could you expand on that please? I'm new to SoapUI. What can i put in the expected results field of my Xpath Match assertion that can point back to a previous test case?
    I'm trying to compare two xml responses, which must mirror each other exactly.

    Thanks!
    • OOTesting's avatar
      OOTesting
      Occasional Contributor

      Hi,

       

      I am new to SOAPUI (free) and would like to know how you can use xpath match to check 2 XML responses.

       

      Specifically how you can setup the source from the 1st XML response into the second XML response - xpath match assertion.

       

      If you can provide a example, that would be brilliant

       

       

       

      • groovyguy's avatar
        groovyguy
        Champion Level 1

        You may want to consider starting your own thread, as opposed to ressurrecting a long-dead thread. 

  • nmrao's avatar
    nmrao
    Champion Level 3
    Here is call to the mentioned library in the groovy script where actual and expected are two xml objects and returns true if both are same, false otherwise.
    DeepEquals.deepEquals(actual, expected)