How to use XmlSlurper in soapUI
I have the below groovy script which I run in groovyconsole and it runs just fine. I'm finding the number of child nodes for a particular node in my xml response and printing out required values for each child node.
def path = new XmlSlurper().parse(new File('C://SoapUI//ResponseXML/Response.xml'))
NumberOfPositions = path.Body.GetPositionsAggregateResponse.GetPositionsAggregateResult.AccountPositions.Securities.Positions.children().size()
for(def i=0; i<NumberOfPositions; i++){
println i
println path.Body.GetPositionsAggregateResponse.GetPositionsAggregateResult.AccountPositions.Securities.Po开发者_StackOverflow社区sitions.PositionSummary[i].Legs[0].PositionAggregate[0].PositionID[0].text()
println path.Body.GetPositionsAggregateResponse.GetPositionsAggregateResult.AccountPositions.Securities.Positions.PositionSummary[i].Legs[0].PositionAggregate[0].AccountID[0].text()
}
I want to perform the same task in soapUI, but couldn't get it working using groovyutils as mentioned here : http://www.soapui.org/Scripting-Properties/tips-a-tricks.html
1) How do I parse the xml response from my request to xmlSlurper? def path = new XmlSlurper().parse (?)
2) Would I be able to use the same code above in soapUI too?
Any help is appreciated. Thanks!
(1)
For parsing the response message you could try the following:
def response = context.expand( '${TestRequest#Response}' )
def xml = new XmlSlurper().parseText(response)
TestRequest
represents the name of your test step which is sending the SOAP request message.
(2)
Yes, soapUI should be able to handle any Groovy code.
You can directly use normal groovy script in SoapUI. Check this link, it might help you. But, remember that instead of "println' You need to use "log.info" while scripting in SoapUI.
精彩评论