使用 groovy 更改 SoapUI 请求

发布于 2024-12-05 06:00:27 字数 1018 浏览 0 评论 0原文

我是 SoapUI 的新手。我有几个相互依赖的测试步骤。因此,我使用 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();

I'm new to SoapUI. I have a few TestSteps depending on each other. So i used the XML-Slurper to read Data from a response "deliverData" and stored them in my TestCase's properties.

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

   <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? 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!
john

ANSWER:
this is how it works, but not with the xmlslurper any more.

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "DeliverStatus#Request" );
holder.setNodeValue( "//DeliverRequest", "200" );
holder.updateProperty();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩世 2024-12-12 06:00:27

下面的代码可以帮助您解决问题。

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)

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)
初雪 2024-12-12 06:00:27

您拥有属性 pollingID,只需在另一个 SOAP 请求中使用该属性值,如下所示。

<soapenv:Body>
    <DeliverRequest>${Properties#pollingID}</DeliverRequest>               
</soapenv:Body>

它可能会从该属性中获取数据,并且您可以在整个测试用例中使用它[属性]。

如果您想在测试用例之间共享数据,请将其存储为测试套件属性,并在任何测试用例中像 ${#TestSuite#Property.name} 一样使用它。

You have property pollingID and just use that property value in another SOAP request, like the below.

<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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文