Forum Discussion
Gkm
Contributor
I don't know how to do this by loop
nmrao
8 years agoChampion Level 3
Here is loop thru jdbc result rows example.
http://stackoverflow.com/questions/37659410/soapui-pro-how-to-dynamically-create-soap-request-by-adding-collection-objects/37663508#37663508
http://stackoverflow.com/questions/37659410/soapui-pro-how-to-dynamically-create-soap-request-by-adding-collection-objects/37663508#37663508
- Gkm8 years agoContributor
Great thanks let me try first :)
btw can do same fashion with this JSON response ?
- nmrao8 years agoChampion Level 3Of course. Here is an example:
https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/AssertJsonArrayElement.groovy- Gkm8 years agoContributor
I have to add separate array for CDATA string , here is the code I'm able to get all JDBC values.
import com.eviware.soapui.support.XmlHolder import groovy.json.* import groovy.xml.* def response = ''' <Results> <ResultSet fetchSize="128"> <Row rowNumber="1"> <CONFIGURATIONDETAILXML> <![CDATA[ <ROOT> <Profile>12</Profile> <BitRate>3072</BitRate> <VideoDevice> <Id>1</Id> <Devices>[{"Name":"ALPR_1","Profile":{"ID":1,"BitRate":0},"Index":-1}]</Devices> <PIPDevices> <Devices>[{"Name":"ALPR_2","Profile":{"ID":2,"BitRate":0},"Mode":"pip"}]</Devices> </PIPDevices> </VideoDevice> </ROOT> ]]> </CONFIGURATIONDETAILXML> <UNITID>Gita</UNITID> </Row> </ResultSet> </Results> ''' def holder = new XmlHolder(response) def configurationXmlCdata = holder.getNodeValue('//*:CONFIGURATIONDETAILXML') def XmlCdata = new XmlSlurper().parseText(configurationXmlCdata) def Cdatajdbc = [] XmlCdata.each { row -> Cdatajdbc.addAll(row.Profile,row.VideoDevice) log.info Cdatajdbc } def jdbcResponseSlurper = new XmlSlurper().parseText(response) def jdbc = [] jdbcResponseSlurper.ResultSet.Row.each { row -> jdbc.addAll(row.UNITID) log.info jdbc }
But I'm getting error in case of JSON ,
//def JSONResponse = context.expand('${unitconfig#Response}') def JSONResponse = ''' "{\"Unit\":{\"Profile\":12,\"Devices\":[{\"Id\":1,\"DetailJSON\":\"[{\\\"Name\\\":\\\"ALPR_1\\\",\\\"Profile\\\":{\\\"ID\\\":1,\\\"BitRate\\\":0},\\\"Index\\\":-1}]\",\"PIPDetailJSON\":[\"[{\\\"Name\\\":\\\"ALPR_2\\\",\\\"Profile\\\":{\\\"ID\\\":2,\\\"BitRate\\\":0,\\\"Mode\\\":\\\"pip\\\"}]\"]}],\"UnitID\":12}" ''' def TrimResponse =JSONResponse.replaceAll('^\"|\"$','').replaceAll('\\\\','').replaceAll('\"\\[','')replaceAll('\\]\"','') def jsonResponseSlurper = new JsonSlurper().parseText(TrimResponse) log.info jsonResponseSlurper.Unit.Profile // 12 is displaying def json = [] jsonResponseSlurper.Unit.each { r -> json.addAll(r.Profile) // error displays log.info json }
- ERROR:groovy.lang.MissingPropertyException: No such property: Profile for class: java.util.HashMap$Entry
Related Content
- 6 years agopankajmalinda
- 7 years agoKate
- 7 years agomoolickj
- 2 years agoYurie