Forum Discussion

vikramwarudkar's avatar
13 years ago

Put assertions on XML response

Hi,

I am working with SOAP free version.
I have a SOAP request. Response of which is received in three different formats. (XML, JSON, HTML)
I want put assertions on XML response.
If I add assertion, by default it is putting those assertions on HTML foramt response.
Do I need to do any special setting? Please suggest.

Thanks a lot.
Vikram
  • nmrao's avatar
    nmrao
    Icon for Champion Level 2 rankChampion Level 2
    Do you get the response in multiple formats for the same request? How do you tell in which format response is expected? I haven't seen such as so far, interesting.

    May be you can have script assertion, and check the response is xml.

    Here is some sample script to check :

    import groovy.xml.*
    def xml = '''
    <books xmlns:meta="http://meta/book/info" count="3">
    <book id="1">
    <title lang="en">Groovy in Action</title>
    <meta:isbn>1-932394-84-2</meta:isbn>
    </book>
    <book id="2">
    <title lang="en">Groovy Programming</title>
    <meta:isbn>0123725070</meta:isbn>
    </book>
    <book id="3">
    <title>Groovy &amp; Grails</title>
    <!--Not yet available.-->
    </book>
    <book id="4">
    <title>Griffon Guide</title>
    </book>
    </books>
    '''
    def books = new XmlSlurper().parseText(xml).declareNamespace([meta:'http://meta/book/info'])
    assert books instanceof groovy.util.slurpersupport.GPathResult

    Hope this helps.

    Regards,
    Rao.