Forum Discussion

Perchishka's avatar
Perchishka
Occasional Contributor
8 years ago

Groovy script for JDBS request assertion. Unexpected element: CDATA

Hello!

 

I just started to use SOAPUI

I have a script assertion for JDBC request:

 

import com.eviware.soapui.support.XmlHolder

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "JDBC Request#ResponseAsXml" )


s = holder.getNodeValue("//PS_SUBSCRIBE_DATA_290.CREATED_DATE") 
log.info (s)
 assert s != null

Yesterday this script worked  and assertion passed.

But today  i see an error: Unexpected element: CDATA

 

Could you help me please! What is wrong?

 

  • PaulMS's avatar
    PaulMS
    8 years ago

    If you renamed the test step then you need to update this line in the script

    def holder = groovyUtils.getXmlHolder( "JDBC Request#ResponseAsXml" )

  • Perchishka's avatar
    Perchishka
    Occasional Contributor
    <Results>
        <ResultSet fetchSize="0">
            <Row rowNumber="1">
                <PS_SUBSCRIBE_DATA_290.CREATED_DATE>2016-11-14  16:35:27</PS_SUBSCRIBE_DATA_290.CREATED_DATE>
                <PS_SUBSCRIBE_DATA_290.CHANGED_DATE>2017-01-27 13:40:33.911</PS_SUBSCRIBE_DATA_290.CHANGED_DATE>
           </Row>
        </ResultSet>
    </Results>

    This is my response for jdbc request

    • nmrao's avatar
      nmrao
      Champion Level 3
      does not have any cdata in there?
  • Perchishka's avatar
    Perchishka
    Occasional Contributor

    I have only this xml response :smileysad: without any CDATA

    And in the response window i have only one inset - "XML"

     

    • PaulMS's avatar
      PaulMS
      Super Contributor

      If you renamed the test step then you need to update this line in the script

      def holder = groovyUtils.getXmlHolder( "JDBC Request#ResponseAsXml" )

    • Radford's avatar
      Radford
      Super Contributor

      I'm not sure why you script assertion is not working, but a couple of pointers:

       

      1) Does your JDBC test step have a "JDBC Status" assertion? Probably not relavent but I always like to have one first just to give me confidence that there was nothing wrong with the SQL call.

       

      2) An alternative to using the XML holder would be the following code, which may be worth trying to help track down your error :

       

      def s = context.expand( '${JDBC Request#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/PS_SUBSCRIBE_DATA_290.CREATED_DATE[1]}' )
      log.info(s)
      assert s

       

      One important point to note is that if the XML element does not exist, the context.expand will return an empty string, thus the assertion uses the fact that Groovy Truth will mean that both null and empty strings will assert to false.

  • Perchishka's avatar
    Perchishka
    Occasional Contributor

    Thank you very much,  guys!

    Your advice was helpful!

    I renamed the test step and it was a mistake.

     

     and i had to edit  this line  =>( "JDBC Request#ResponseAsXml" )