xml - 使用 groovy 更改 SoapUI 请求

标签 xml groovy soapui

我是 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/

相关文章:

java - 使用 java 缩进遍历所有 XML 标签

date - Groovy 在 00 :00:00 分钟获取今天的日期

groovy - 有人可以解释一下 geb 页面内容 DSL 中的语法吗?

xml - 为什么 XSD 中的 "maxLength"属性不限制返回的字符数?

c# - 停止线程直到有足够的内存可用

java - XmlPullParser 找不到名称中带有冒号的属性

mysql - 在groovy中调用mysql存储过程

soapui - 如何在Postman中导入SoapUI项目?

web-services - 使用 SoapUI 时出现问题 : "A required header representing a Message Addressing Property is not present

java - 在 Java 中测试 SOAP Web 服务