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,

<UserProfile>
            <ID>${#DataInput#UserId}</ID>
            <StartDate>${#DataInput#A1StartDate}</StartDate>
            <EndDate>${#DataInput#A1EndDate}</EndDate>
            <SerialID>${#DataInput#SerialId}</SerialID>
            <AccountID>${#DataInput#MaterialId}</AccountID>
</UserProfile>

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 com.eviware.soapui.support.GroovyUtils( 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")
outputFile.append(requestAsXml)
outputFile.append("=========================================================")

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.