Forum Discussion

amit_db's avatar
amit_db
New Contributor
8 years ago
Solved

Not able to add xpath assertion on a complex REST API response

Hi,     I am using SoapUI 5.2.1 (free version). I am testing a REST API and trying to add assertion to the response message I am getting. Problem is that the response I am getting is not simple, t...
  • nmrao's avatar
    8 years ago

    amit_db,

     

    Mr KarelHusa provided already a solution and a suggestion to use regular expression.

     

    Here is another way using Script Assertion:

     

     

    /**
    * Closure to search for certain element data
    * input parameters
    * xml data, element name to search
    **/
    def searchData = { data, element ->
       def parsedData = new XmlSlurper().parseText(data)
       parsedData.'**'.find { it.name() == element} as String
    }
    
    //Check if there is any thing in response
    assert context.response, "Response is empty or null"
    
    //Get the cdata part which is inside element "pre"
    def cData = searchData(context.response,'pre')
    assert cData, "CDATA is empty or null"
    
    //Get the instrumentId from cdata
    def instrumentId = searchData(cData, 'InstrumentRUID')
    
    //Check if that is matching.
    assert '16133645' == instrumentId, "InstrumentId is not matching"