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,

<br />
&lt;UserProfile&gt;<br />
            &lt;ID&gt;${#DataInput#UserId}&lt;/ID&gt;<br />
            &lt;StartDate&gt;${#DataInput#A1StartDate}&lt;/StartDate&gt;<br />
            &lt;EndDate&gt;${#DataInput#A1EndDate}&lt;/EndDate&gt;<br />
            &lt;SerialID&gt;${#DataInput#SerialId}&lt;/SerialID&gt;<br />
            &lt;AccountID&gt;${#DataInput#MaterialId}&lt;/AccountID&gt;<br />
&lt;/UserProfile&gt;<br />

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.

<br />
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )<br />
def requestHolder = groovyUtils.getXmlHolder( messageExchange.requestContent )<br />
def requestAsXml=requestHolder.getXml();</p>
<p>def outputDirectory =  context.expand( '${#Project#OutputDirectory}' )<br />
def testName =  context.expand( '${#Project#TestName}' )<br />
def makeDirectory = new File(outputDirectory).mkdir()<br />
def outputFile=new File(outputDirectory + testName + &quot;.xml&quot;)<br />
outputFile.append(requestAsXml)<br />
outputFile.append(&quot;=========================================================&quot;)<br />

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.