2011-04-24 46 views
0

我有下面的groovy腳本,我在groovyconsole中運行,它運行得很好。我在xml響應中查找特定節點的子節點數,併爲每個子節點輸出所需的值。如何在soap中使用XmlSlurperUI

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中使用上面相同的代碼?

任何幫助表示讚賞。謝謝!

回答

2

(1)
對於解析響應消息,你可以嘗試以下方法:

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

TestRequest代表你的測試步驟被髮送SOAP請求消息的名稱。

(2)
是的,soapUI應該能夠處理任何Groovy代碼。

0

你可以在SoapUI中直接使用普通的groovy腳本。檢查這個link,它可能會幫助你。但是,請記住,而不是「println」您需要在SoapUI腳本中使用「log.info」。