Forum Discussion
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" ?
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 )
- richie4 years agoCommunity 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
- UnnounUsername4 years agoOccasional Contributor
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.- richie4 years agoCommunity HeroHey 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