A Quick SoapUI Guide to Store Request and Response Data in a File – SoapUI Tutorial #15

In this SoapUI advance tutorial, let’s learn about how to store the response in a file for future reference. Also, the steps are very detailed, so we treat this as a quick recap of everything we do, end-to-end.

This is the last tutorial in our SoapUI free training series. Head over to this page for all the tutorials in this comprehensive SoapUI and SoapUI pro tutorials series.

soapui tutorial 15

Storing Request and Response in a File:

We will start from creating SOAP project:

  1. Open SoapUI Pro
  2. In the Navigator panel, right click on the Project
  3. From the context menu, click on New SOAP Project option.(You can also use Ctrl+N)
  4. New SOAP Project dialogue appears on the screen.
  5. In the New SOAP Project window, enter the project name, StoreResponseValueInFile.
  6. click OK
  7. Now the project is created successfully without any test steps as we did not include WSDL document

Adding WSDL

Let us add currency converter WSDL in this section.

1) In the project tree, right click on the project name that was created in the previous section. i.e. StoreResponseValueInFile

2) In the popup menu, click Add WSDL option. Refer the following screenshot.

exporting data in file 1

3) In the Add WSDL window, enter the currency converter URL.

4) Click OK

5) We can now see the StoreResponseValueInFile project under the project tree along with the interface steps. If you expand a web service (i.e. ConversionRate), there will be a node known as Request1 by default.

6) Double click on the Request1 node to view the request XML content. You could rename it if needed.

Add Test Suites and Test Cases

  1. In the project tree, right-click on the CurrencyConvertorSoap interface.
  2. From the popup menu, click the Generate Test Suite option.
  3. Leave the default settings in and click OK.
  4. Enter the test suite name in the given text field, SampleTestSuite, and click OK.
  5. Now test suite is created along with the test case name, ConversionRate TestCase.
  6. Rename the test case name as SampleTestCase by right-clicking on the test case name and click the Rename option.

Add Groovy Steps

1) Under sample test suite, right click on the sample test case node

2) From the popup menu, click Add Step -> Groovy Script test step

3) Enter name of the groovy script as GetResponseValue and click OK

4) Groovy script test step is added to the test suite and redirected to the script editor.

5) In the editor, add the following script.

def response = context.expand( ‘${ConversionRate – Request 1#Response}’ )
new File( “D:/Groovy/” + “_response.txt” ).write( response )

Note: You should have executed the ConversionRate request with required input parameters.

6) Double click on the SampleTestSuite -> SampleTestCase -> TestSteps(2) -> ConversionRate – Request1

7) Click on the XML tap from the Vertical tab bar

8) Here, replace the following input data instead of a question mark (?) in the soap code.

  • FromCurrency = USD
  • ToCurrency = INR

9) Double click on SampleTestSuite -> SampleTestCase -> TestSteps(2) -> GetResponseValue

10) Now Run the TestSuite by clicking on this icon.

Now we are done storing response data in our local drive.

Verify the response in the response tab and also in the hard drive to ensure both responses are identical.

We can also save the request information in a file. For that, do the following.

1) Right click on the script editor and then click Get Data -> Step 1 [ConversionRate] -> Property [Request] option. Refer the following screenshot.

exporting data in file 2

2) SoapUI Pro will give you auto-generated code like this.

def request = context.expand( ‘${ConversionRate#Request}’ )

3) Then add the following script in the next line

new File( “D:/groovy/” + “_request.txt” ).write( request )

If we execute this script, we will get a file with the name of _request.txt in our local drive as mentioned in the script.

Here are some tips about storing raw request through groovy scripting. Take a look at the following sample scripts.

testCase.getTestStepByName(<teststep name>).getProperty(“Request”).getValue()

The above scripts are used to get the raw web service request while executing the test step. Following the script, we can write another line to receive request information in the variable as we have seen in the above samples. See the below sample code to understand this better.

def request = testCase.getTestStepByName(“ConversionRate”).getProperty(“Request”).getValue()
new File( “D:/GroovyRequest/” + “RawRequestData.txt” ).write( request )


That brings us to an end, not only of this article, but the entire series. We hope this has been useful to you and brought you closer to your SoapUI learning skills. As always, practice, patience and persistence are the most as important as the tutorials themselves for best results.

As a recap of everything you learned in this SoapUI training series, we will be having one SoapUI interview questions and answers tutorial in the end.

We are here to hear your thoughts, experiences and of course, answer questions should you have any.

Thank you for sticking around with us!

Related Post

Leave a Reply

Your email address will not be published.