如何在soapUI中使用XmlSlurper

发布于 2024-11-03 13:05:43 字数 1108 浏览 1 评论 0原文

我有下面的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场信仰旅途 2024-11-10 13:05:43

(1)
要解析响应消息,您可以尝试以下操作:

def response = context.expand( '${TestRequest#Response}' )
def xml = new XmlSlurper().parseText(response)

TestRequest 表示发送 SOAP 请求消息的测试步骤的名称。

(2)
是的,soapUI 应该能够处理任何 Groovy 代码。

(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.

苍暮颜 2024-11-10 13:05:43

您可以直接在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文