2011-09-20 88 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}