如何在soapUI中使用XmlSlurper
我有下面的 groovy 脚本,我在 groovyconsole 中运行它,它运行得很好。我在 xml 响应中查找特定节点的子节点数量,并打印每个子节点所需的值。
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.Positions.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()
}
我想在soapUI中执行相同的任务,但无法使用此处提到的groovyutils使其工作: http://www.soapui.org/Scripting-Properties/tips-a-tricks.html
1) 如何解析我的请求的 xml 响应xmlSlurper? def path = new XmlSlurper().parse (?)
2) 我也可以在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.Positions.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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(1)
要解析响应消息,您可以尝试以下操作:
TestRequest
表示发送 SOAP 请求消息的测试步骤的名称。(2)
是的,soapUI 应该能够处理任何 Groovy 代码。
(1)
For parsing the response message you could try the following:
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.
您可以直接在 SoapUI 中使用普通的 groovy 脚本。检查此链接,它可能会对您有所帮助。但是,请记住,在 SoapUI 中编写脚本时,您需要使用“log.info”,而不是“println”。
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.