[英]Change SoapUI Request with groovy
I'm new to SoapUI. 我是SoapUI的新手。 I have a few TestSteps depending on each other.
我有几个TestSteps相互依赖。 So i used the XML-Slurper to read Data from a response "deliverData" and stored them in my TestCase's properties.
所以我使用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());
Now i want to use the pollingID for another request which like this 现在我想将pollingID用于另一个像这样的请求
<soapenv:Body>
<DeliverRequest>?</DeliverRequest>
</soapenv:Body>
I read http://groovy.codehaus.org/Updating+XML+with+XmlSlurper but I do not see how to store manipulated data into the request? 我阅读了http://groovy.codehaus.org/Updating+XML+with+XmlSlurper,但我没有看到如何将操纵数据存储到请求中? I'm not even sure about how to update.
我甚至不确定如何更新。 Hope anybody can help me, i really do not like working with scripts, i prefer normal java coding:) Thanks a lot!
希望有人可以帮助我,我真的不喜欢使用脚本,我更喜欢正常的java编码:)非常感谢! john
约翰
ANSWER: this is how it works, but not with the xmlslurper any more. 答案:这是它的工作原理,但不再是xmlslurper了。
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "DeliverStatus#Request" );
holder.setNodeValue( "//DeliverRequest", "200" );
holder.updateProperty();
The below code may help you sort your issue. 以下代码可帮助您对问题进行排序。
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)
You have property pollingID
and just use that property value in another SOAP request, like the below. 您有属性
pollingID
,只需在另一个SOAP请求中使用该属性值,如下所示。
<soapenv:Body>
<DeliverRequest>${Properties#pollingID}</DeliverRequest>
</soapenv:Body>
it might fetch data from that property and you can use it [property] throughout the Test Case. 它可能从该属性中获取数据,您可以在整个测试用例中使用它[属性]。
If you want to share data between Test cases store it as Test suite property and use it like ${#TestSuite#Property.name}
in any of the test case. 如果要在测试用例之间共享数据,请将其存储为测试套件属性,并在任何测试用例中使用它,如
${#TestSuite#Property.name}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.