Forum Discussion

MKV's avatar
MKV
Contributor
6 years ago
Solved

Compare XML response with DB values

How to compare the XML Response values with DB query output values in Ready API?

  • If you put a Groovy test step after your JDBC request, you could then use property expansions to get your data and perform an assertion, something like:

     

    def soapDataItem = context.expand('${SOAP Request#Response#//Blah[1]/DataItem[1]}')
    def jdbcDataItem = context.expand('${JDBC Request#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/ITEM[1]}')
    
    log.info('soapDataItem = ' + soapDataItem)
    log.info('jdbcDataItem = ' + jdbcDataItem)
    
    assert soapDataItem == jdbcDataItem

     

    Note: I've just made up the property expansions as an example, To get your actual data from within the Groovy script editor you can always use the right click menu "Get Data" option. This allows you to construct your property expansion via a visual point and click method.

     

    An alternative to the above Groovy method, might be to put an Assertion Test Step after the JDBC test step, using this instead.

4 Replies

  •  

    Use Xmlholder to get the nodeValue or values method as per your requirement. if you use nodevalues method then iterate it and store the values in string or set the values @ any property level project/testsuite/testcase as per your requirement  and then compare the two values using .equals method of String class. I am assuming you must be saving db column values some where inthe code. 

    /*for (def item in arr)
    {
    log.info item
    }*/

     

    import com.eviware.soapui.support.XmlHolder
    def req= context.expand ('${SOAPRequest#request}')
    def res=context.expand ('${SOAPRequest#response}')

    def xml=new XmlHolder(res)

    log.info xml.getNodeValue("//m:dGame[1]")

    def arr=xml.getNodeValues ("//m:dGame")

  • Radford's avatar
    Radford
    Super Contributor

    Is the is DB query output from a JDBC Request Test Step? If so can you not just use an XPath Match Assertion on your XML response?

     

    This can simply be created from the outline view of your XML response, just right click the value in question, and select the 'Add Asserstion...' > 'for Content' option, and then use the 'Select Content' drop down to select the data from your JDBC test step.

    • MKV's avatar
      MKV
      Contributor

      I'm trying to compare the values in iterative manner.

      My scenario is pick the customer id from DB and pass it to request. Validate all the response values against a DB value for all the customers.

      I tried to create the test case as below:

      1. DataSource - To query the data for request

      2. SOAP Request - Picks the I/P data from Datasource

      3. JDBC Request - Picks the data from Datasource to be used in SQLQuery

      4. DataSource Loop - From DataSource to SOAP Request

       

      I tried to validate for a sample response data (customer id). In case of a single data, I'm able to do with Content Assertion, If it doesnt help iteratively.

       

      Please suggest.

      • Radford's avatar
        Radford
        Super Contributor

        If you put a Groovy test step after your JDBC request, you could then use property expansions to get your data and perform an assertion, something like:

         

        def soapDataItem = context.expand('${SOAP Request#Response#//Blah[1]/DataItem[1]}')
        def jdbcDataItem = context.expand('${JDBC Request#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/ITEM[1]}')
        
        log.info('soapDataItem = ' + soapDataItem)
        log.info('jdbcDataItem = ' + jdbcDataItem)
        
        assert soapDataItem == jdbcDataItem

         

        Note: I've just made up the property expansions as an example, To get your actual data from within the Groovy script editor you can always use the right click menu "Get Data" option. This allows you to construct your property expansion via a visual point and click method.

         

        An alternative to the above Groovy method, might be to put an Assertion Test Step after the JDBC test step, using this instead.