Forum Discussion
Hi,
Where you say names that are more than 500, what exactly do you mean? And how do you want the output of the extraction to be?
For eaxample, if you mean extract JSON documents (maybe log or store in a variable) which have a 'number' property >500 then that should be fairly OK to do in a Groovy script.
Let me know,
Rup
- Sphujidhwaj9 years agoContributor
Hi Rup,
When I say names more than 500 it means the count of names,I have more than 500 blocks or chunks of names to be extracted.
Still I have not got there yet I am first trying to extract the data from the CData
But encountering the following message.
groovy.lang.MissingPropertyException: No Such Property: messageExchange for class: Script8 error at line 3
import com.eviware.soapui.support.XmlHolder respXmlHolder = new xmlHolder(messageExchange.getResponseContentAsXml()) respXmlHolder.declareNamespace("ns1","http://tempuri.org/") CDATAXml = respXmlHolder.getNodeValue("//ns1:Result") log.info(CDATAXml)
Please let me know where I am going wrong. Are there any links for the same where I can get some assistance in debugging such errors.
Thanks,
SD
- nmrao9 years agoChampion Level 3
Also you check this example which is done some recently and same as yours ie., xml contains cdata and it contains json.
http://stackoverflow.com/questions/35623183/soapui-how-to-find-node-count-in-json-response/35626696#35626696Other examples to get the json data
https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/AssertJsonArrayElement.groovy
- Sphujidhwaj9 years agoContributor
Hi,
CDATAXml = respXmlHolder.getNodeValue("//ns1:Result") log.info(CDATAXml) def data = new XmlSlurper().parseText(CDATAXml) def list = new groovy.json.JsonSlurper().parseText( data.toString()) log.info list.size()
When I try to run the above script I get an error "Content is not allowed in prolog"
The CDATAXml is very huge (I copied the content in text file it comes around 12000 lines)
Is the error due to huge data?
Please let me know if I am going wrong anywhere.
Thanks,
SD
- nmrao9 years agoChampion Level 3first of all it should be 'XmlHolder', and is case sensitive.
- Sphujidhwaj9 years agoContributor
Yes it is in Caps as shown below
respXmlHolder = new XmlHolder(messageExchange.getResponseContentAsXml())
- rupert_anderson9 years agoValued Contributor
Hi SD,
Ok, so basically if the count of those Report JSON documents goes above 500, then we capture 501+ etc.
OK, maybe we should work on it a step at a time.
1) First we can try to extract the report JSON documents from the response CDATA.
2) Then, we can use JSON Slurper to parse the JSON data into report objects.
3) Then we can try to extract just the report objects where the count is >500
In terms of the error you're getting, at first glance it looks like you're not running the script from a Script Assertion? The messsageExchange variable is only available to script run there:
- rupert_anderson9 years agoValued Contributor
Thats a nice JSON Slurper script example that Rao has provided, that should cover step 2 and part of step 3 :-)
Related Content
Recent Discussions
- 15 years ago