2011-09-20 89 views
3

我是SoapUI的新手。我有幾個TestSteps取決於對方。所以我使用XML-Slurper從響應「deliverData」中讀取數據並將它們存儲在我的TestCase的屬性中。用groovy更改SoapUI請求

def xml = new XmlSlurper().parseText(response) 
def response = context.expand('${deliverData#Response}') 
def ID = xml.Body.DeliverDataResponse."pollingId"; 
testRunner.testCase.setPropertyValue("pollingID",ID.text()); 

現在我想用pollingID針對這樣

<soapenv:Body> 
     <DeliverRequest>?</DeliverRequest> 
    </soapenv:Body> 

我讀http://groovy.codehaus.org/Updating+XML+with+XmlSlurper另一個請求,但我不明白如何操作數據存儲到要求嗎?我甚至不確定如何更新。 希望有人能幫助我,我真的不喜歡使用腳本,我更喜歡普通的java編碼:) 非常感謝! john

回答: 這是它是如何工作的,但不是與xmlslurper一樣。

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) 
def holder = groovyUtils.getXmlHolder("DeliverStatus#Request"); 
holder.setNodeValue("//DeliverRequest", "200"); 
holder.updateProperty(); 

回答

1

以下代碼可能會幫助您排序問題。

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) 
// get XmlHolder for request message def 

holder = groovyUtils.getXmlHolder("CelsiusToFahrenheit#Request") 

holder1 = groovyUtils.getXmlHolder("FahrenheitToCelsius#Request") 

// Pass value to request node 
holder["//tem:Celsius"] = "100" 

// write updated request back to teststep 
holder.updateProperty() 

// Run the Request 
testRunner.runTestStepByName("CelsiusToFahrenheit") 

// Get the response value in a variable 
def response = context.expand('${CelsiusToFahrenheit#Response#declare namespace ns1=\'http://tempuri.org/\'; //ns1:CelsiusToFahrenheitResponse[1]/ns1:CelsiusToFahrenheitResult[1]}') 
log.info(response) 


// Pass the new value to another request 
holder1["//tem:Fahrenheit"] = response 
holder1.updateProperty() 

// run the test request 
testRunner.runTestStepByName("FahrenheitToCelsius") 

def response1 = context.expand('${FahrenheitToCelsius#Response#declare namespace ns1=\'http://tempuri.org/\'; //ns1:FahrenheitToCelsiusResponse[1]/ns1:FahrenheitToCelsiusResult[1]}') 
log.info(response1) 
0

您有財產pollingID,只是在另一個SOAP請求中使用該屬性值,如下所示。

<soapenv:Body> 
    <DeliverRequest>${Properties#pollingID}</DeliverRequest>    
</soapenv:Body> 

它可能會從該屬性獲取數據,並且您可以在整個測試用例中使用它[屬性]。

如果要在測試用例之間共享數據,請將其存儲爲測試套件屬性,並在任何測試用例中使用它,如${#TestSuite#Property.name}