Forum Discussion

prouser's avatar
prouser
Contributor
12 years ago

Access JDBC test step response in Groovy test step

Hi All

I am trying the count the records retrieved from the JDBC test step in a groovy test step

I am facing difficulty in coming up with xpath for the xml response

Here is the sample response in my JDBC test step

<Results>
<ResultSet fetchSize="64">
<Row rowNumber="1">
<TBC_ID>29379155</TBC_ID>
<TBC_DATE>2013-01-31</TBC_DATE>
</Row>
<Row rowNumber="2">
<TBC_ID>29379576</TBC_ID>
<TBC_DATE>2013-01-31</TBC_DATE>
</Row>

Here is my Groovy script to access this JDBC response

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def db_response = context.expand( '${JDBC Request#Response#//Results/ResultSet}' )
log.info db_response
def resxml = new XmlSlurper().parseText(db_response)
allnodes = resxml.Row
log.info "Nodes Size: "+allnodes.size()

This is not printing desired output(JDBC response xml in this case) and throwing an error "Premature end of file" at the following step
def resxml = new XmlSlurper().parseText(db_response)
  • SiKing's avatar
    SiKing
    Community Expert
    It's "ResposeAsXml"!
    You could get the count simply by
    def rowCount = context.expand( '${JDBC Request#ResponseAsXml#count(//Row)}' ).toInteger()
  • Thank you . Yes it worked

    Could you tell me how we can know when it is appropriate to use Response/ResponseAsXml.
    Also are there are any other keywords for such purpose?
  • SiKing's avatar
    SiKing
    Community Expert
    In the GUI, when you are looking at the Response tab, have a look at the "Raw" display. Only the SOAP step produces Raw XML. Everything else produces something else in the Raw output, and SoapUI internally converts that asXml.