Forum Discussion

UnnounUsername's avatar
UnnounUsername
Occasional Contributor
4 years ago

Property Transfers get sid from the CDATA

Hi all, can anybody halp with such problem. I got the response and now need to get sid (YkhXK0uq6HBPvn3zAAAE) from the xml CDATA

 

<data contentType="text/plain; charset=UTF-8" contentLength="97"><![CDATA[0{"sid":"YkhXK0uq6HBPvn3zAAAE","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":20000}]]></data>

 

 i tried this one (based on this)

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def response = context.expand('${GET GetSID#ResponseAsXml}')
def holder = groovyUtils.getXmlHolder(response)

node_data = holder.getNodeValue("//data")
context.sid = node_data.replaceAll("sid:", "");

log.info context.sid

 

but it leds to error

is it possible to get sid without groovy just to use the Property Transfers ?

 

  • UnnounUsername's avatar
    UnnounUsername
    4 years ago

    the solution was found, it is not very pretty but works

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def response = context.expand('${GetSID - GetSID#ResponseAsXml}')
    def holder = groovyUtils.getXmlHolder(response)
    node_data = holder.getNodeValue("//data")
    String str = node_data; 
    //get data between the text   
    String result1 = str.substring(str.indexOf("sid") + 1, str.indexOf("upgrades"));
    //delete all extra symbols in the string
    String result2 = result1.replaceAll('"',"")
    String result3 = result2.replaceAll(":","")
    String result4 = result3.replaceAll("id","")
    String result = result4.replaceAll(',',"")
    //set global variable
    com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "sid", result )
  • richie's avatar
    richie
    4 years ago

    Hey UnnounUsername 

     

    Apologies - Ive only just seen your post.  I can see you've already sorted this out, but for future reference, there is an alternative option to relying on groovy script when attempting to extract values from CDATA wrapped xml - you can actually use the embedded functionality instead.

     

    Essentially the short answer is to use a property within a property.

     

    If you launch --> https://www.soapui.org/docs/functional-testing/working-with-cdata/

     

    Navigate to section '3. Property Transfers and CDATA Sections' and follow these instructions.  I've used this option a couple of times - it's not pretty either - but it gets the job done!

     

    Cheers,

     

    Rich

  • UnnounUsername's avatar
    UnnounUsername
    Occasional Contributor

    got a little bit off the ground

     

     

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def response = context.expand('${GetSID - GetSID#ResponseAsXml}')
    def holder = groovyUtils.getXmlHolder(response)
    log.info holder
    node_data = holder.getNodeValue("//data")
    context.sid = node_data.replaceAll("sid:\"", "");
    
    log.info context.sid

     

     

    it returns

    0{"sid":"3qMphUliksaYTtl1AAAG","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":20000}


    but how to get the "3qMphUliksaYTtl1AAAG" ?

    • UnnounUsername's avatar
      UnnounUsername
      Occasional Contributor

      the solution was found, it is not very pretty but works

      def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
      def response = context.expand('${GetSID - GetSID#ResponseAsXml}')
      def holder = groovyUtils.getXmlHolder(response)
      node_data = holder.getNodeValue("//data")
      String str = node_data; 
      //get data between the text   
      String result1 = str.substring(str.indexOf("sid") + 1, str.indexOf("upgrades"));
      //delete all extra symbols in the string
      String result2 = result1.replaceAll('"',"")
      String result3 = result2.replaceAll(":","")
      String result4 = result3.replaceAll("id","")
      String result = result4.replaceAll(',',"")
      //set global variable
      com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "sid", result )
      • richie's avatar
        richie
        Community Hero

        Hey UnnounUsername 

         

        Apologies - Ive only just seen your post.  I can see you've already sorted this out, but for future reference, there is an alternative option to relying on groovy script when attempting to extract values from CDATA wrapped xml - you can actually use the embedded functionality instead.

         

        Essentially the short answer is to use a property within a property.

         

        If you launch --> https://www.soapui.org/docs/functional-testing/working-with-cdata/

         

        Navigate to section '3. Property Transfers and CDATA Sections' and follow these instructions.  I've used this option a couple of times - it's not pretty either - but it gets the job done!

         

        Cheers,

         

        Rich