SOAP UI – Output Request To Local File System

Template driven framework in SOAPUI helps us to parameterize the user data, based on the business scenario. For example,


Creating request in the above fashion, helps us the follow common framework across soapui projects and ease of maintenance. But this introduces a new challenge, about readability of the request, due the run-time population of data. Here is the groovy script that will output the request generated and store it in a local file system.

def groovyUtils = new context )
def requestHolder = groovyUtils.getXmlHolder( messageExchange.requestContent )
def requestAsXml=requestHolder.getXml();

def outputDirectory =  context.expand( '${#Project#OutputDirectory}' )
def testName =  context.expand( '${#Project#TestName}' )
def makeDirectory = new File(outputDirectory).mkdir()
def outputFile=new File(outputDirectory + testName + ".xml")

This script needs to the added to the assertion section. To do this
“Open the SOAP Request -> Find the ‘Assertion’ tab at the bottom of the request -> Click ‘Add New’ Assertion -> Click ‘Script Assertion’ -> Copy the Script and click OK.

Also this script uses two properties,
Create a property at project level named “OutputDirectory” with value “C://output”
Create one more property at project level named “TestName” with value as ‘${Name of the test}’

Please note that this groovy script needs to be added to the assertion and not to the normal groovy step in test steps.