[英]Change SoapUI Request with groovy
我是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)
您有屬性pollingID
,只需在另一個SOAP請求中使用該屬性值,如下所示。
<soapenv:Body>
<DeliverRequest>${Properties#pollingID}</DeliverRequest>
</soapenv:Body>
它可能從該屬性中獲取數據,您可以在整個測試用例中使用它[屬性]。
如果要在測試用例之間共享數據,請將其存儲為測試套件屬性,並在任何測試用例中使用它,如${#TestSuite#Property.name}
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.