Forum Discussion

UnnounUsername's avatar
UnnounUsername
Occasional Contributor
3 years ago
Solved

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">...
  • UnnounUsername's avatar
    UnnounUsername
    3 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
    3 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