Xml 使用groovy更改SoapUI请求
我是SoapUI新手。我有一些相互依赖的测试步骤。因此,我使用XML Slurper从响应“deliverData”读取数据,并将它们存储在测试用例的属性中Xml 使用groovy更改SoapUI请求,xml,groovy,soapui,Xml,Groovy,Soapui,我是SoapUI新手。我有一些相互依赖的测试步骤。因此,我使用XML Slurper从响应“deliverData”读取数据,并将它们存储在测试用例的属性中 def xml = new XmlSlurper().parseText(response) def response = context.expand( '${deliverData#Response}' ) def ID = xml.Body.DeliverDataResponse."pollingId"; testRunner.t
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>
下面的代码可能会帮助您对问题进行排序
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)
您有property
pollingID
,只需在另一个SOAP请求中使用该属性值,如下所示
<soapenv:Body>
<DeliverRequest>${Properties#pollingID}</DeliverRequest>
</soapenv:Body>
${Properties#pollingID}
它可能从该属性获取数据,您可以在整个测试用例中使用它[property]
如果您想在测试用例之间共享数据,请将其存储为测试套件属性,并在任何测试用例中像${{TestSuite#property.name}
一样使用它
<soapenv:Body>
<DeliverRequest>${Properties#pollingID}</DeliverRequest>
</soapenv:Body>