我是 SoapUI 的新手。我有几个相互依赖的 TestSteps。所以我使用 XML-Slurper 从响应“deliverData”中读取数据并将它们存储在我的 TestCase 的属性中。
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 编码:) 非常感谢! 约翰
回答: 这就是它的工作原理,但不再适用于 xmlslurper。
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "DeliverStatus#Request" );
holder.setNodeValue( "//DeliverRequest", "200" );
holder.updateProperty();
最佳答案
以下代码可以帮助您解决问题。
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)
关于xml - 使用 groovy 更改 SoapUI 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7482353/