Applies to ReadyAPI 3.3.1, last modified on August 11, 2020

Your Groovy scripts have access to the XML content of the request and can modify it. You can change the request text before, during the test run, and right before the request is sent.

Availability

There are several ways to run these scripts:

Examples

Change a Request XML

This example sets the password inside a request SOAP message:

Groovy

// Create groovyUtils and XmlHolder for the request of the Sample Request test step.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( 'Test Request - login#Request' )

// Change the node values in the imported XML.
holder["//username"] = "3216431654"
holder["//password"] = "Loginn1123"

// Update the request and write the updated request back to the test step.
holder.updateProperty()
context.requestContent = holder.xml

Remove Empty XML Elements From the Request

You can already remove empty XML nodes by using the Remove Empty Content option. However, it only removes empty end nodes, and can leave empty parent nodes. To remove those, use the following script:

Groovy

// Create groovyUtils and XmlHolder for the request of the Sample Request test step.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( 'Test Request - login#Request' )

// Find nodes that only consist of whitespaces.
for( item in holder.getDomNodes( "//*[normalize-space(.) = '' and count(*) = 0]" )){
    item.removeXobj()
}
// Update the request and write the updated request back to the test step.
holder.updateProperty()
context.requestContent = holder.xml

See Also

Request Editor Interface

Highlight search results