Ask a Question

Property Transfers get sid from the CDATA

SOLVED
UnnounUsername
Occasional Contributor

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

UnnounUsername_0-1633589182196.png

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

UnnounUsername_1-1633589678383.png

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
UnnounUsername
Occasional Contributor

Re: Property Transfers get sid from the CDATA

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 )

View solution in original post

richie
Community Hero

Re: Property Transfers get sid from the CDATA

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

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

7 REPLIES 7
UnnounUsername
Occasional Contributor

Re: Property Transfers get sid from the CDATA

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
Occasional Contributor

Re: Property Transfers get sid from the CDATA

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 )

View solution in original post

richie
Community Hero

Re: Property Transfers get sid from the CDATA

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

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

UnnounUsername
Occasional Contributor

Re: Property Transfers get sid from the CDATA

Thx a lot for your answer, i saw that page but unfortunately couldn't understand how all it works ... i mean saxon parse and search. I always got

Fri Oct 07 10:06:24 EEST 2021	sid	[Error parsing source property [error: Unexpected element: CDATA]]


But anyway i marked your comment as solution.

richie
Community Hero

Re: Property Transfers get sid from the CDATA

Hey @UnnounUsername,

Yeah, instructions are.a but confusing. You dont need to include the saxon parse text in there. Some of the instructions are a bit old.

If you still care i can search for a post i responded to about 2 years ago where i went through it step by step, but it'll probably take me about half hour to find it, so dont wanna search unless you really need it. Happy to do it if you need to, just saying i csnt be bothered unless you do actually want it is all!😁

Nice one!

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
UnnounUsername
Occasional Contributor

s Re: Property Transfers get sid from the CDATA

Hi, it would be great to see UI solution instead of scripting.

richie
Community Hero

Re: s Re: Property Transfers get sid from the CDATA

Hey @UnnounUsername 

 

have a look at the following link.  Someone posted this a couple of years ago and I posted step by step instructions on how to proceed extracting the value he wanted

 

https://community.smartbear.com/t5/ReadyAPI-Questions/How-extract-html-string-from-json-response/m-p...

 

Cheers,

 

Rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
cancel
Showing results for 
Search instead for 
Did you mean: