Forum Discussion

OOTesting's avatar
OOTesting
Occasional Contributor
9 years ago

Compare 2 XML responses for mismatches

HI,

 

Is it possible to compare 2 XML responses from a test steps which are using different endpoints and then compare the XML responses for any differences.

 

I am using SOAPUI (free)

 

Thank you

  • You can write a groovy script to do so.

    It might be the case that the two responses might be in different format, need to first be in the same format to be able to compare.

    Another thing to consider is that are there any variable data i.e., numbers, dates, uuid etc which never gets matched and to be ignored.
  • nmrao's avatar
    nmrao
    Champion Level 3
    You can write a groovy script to do so.

    It might be the case that the two responses might be in different format, need to first be in the same format to be able to compare.

    Another thing to consider is that are there any variable data i.e., numbers, dates, uuid etc which never gets matched and to be ignored.
    • OOTesting's avatar
      OOTesting
      Occasional Contributor

      Hi,

       

      Already created a groovy script to compare the outputs.

    • fazlook's avatar
      fazlook
      Frequent Contributor

      How do i compare only the format of 2 XML responses ?

       

      I would like to:

       

      Send a PUT request1 that contains right XML elements -> Get RESPONSE1 format (i dont care about the inside content)

      Send a PUT request2 that contains same XML elements but in a different order -> Get same RESPONSE1 format (i dont care about the inside content)

       

      I just want to confirm that the response is in the same format of XML elements. nmrao ?

       

       

       

  • Elvisn12's avatar
    Elvisn12
    New Contributor

    Use the below code to compare the value of two responces 

     

    import com.eviware.soapui.support.XmlHolder
    import groovy.json.JsonSlurper

    def response1 = context.expand( '${Getvalue1#Response}' ).toString() // the request Name or variabe
    log.info(response1)
    def slurper = new JsonSlurper()
    def jsons = slurper.parseText response1

     

    def response = context.expand( '${Getvalue2#Response}' ).toString() The request name or variable 
    log.info(response)
    def slurperz = new JsonSlurper()
    def json = slurper.parseText response

    ///log.info(json.EmployeeNumber)
    assert [json]==[jsons].sort{compare}  // compare the two Values responses

     

    It worked for on my end unless if you have issues with Arrays order on the responses