Change SoapUI Request with groovy

18,323

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)
Share:
18,323
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    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();