In this SoapUI tutorial, we will demonstrate how to save request and response data in a file for future use. The procedure will be discussed in depth to ensure complete understanding.
Before we begin, it’s worth mentioning that this is the concluding tutorial in our SoapUI training series which is completely free. If you haven’t yet, you can access all the previous tutorials in this all-encompassing series here. Let’s get started!
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
Topics Covered:
Saving Request and Response in a File
Initially, we have to set up a SOAP project:
- Launch SoapUI Pro
- In the Navigator panel, right-click on Project
- Select “New SOAP Project” from the context menu (You can also use Ctrl+N as a shortcut)
- A window titled “New SOAP Project” will pop up
- Name the project “StoreResponseValueInFile” in the respective field in the “New SOAP Project” window
- Press OK
- You have now successfully generated the project without any test steps as we didn’t include a WSDL document
Integrating WSDL
In this segment, we will introduce the currency converter WSDL:
1) Right-click on the previously created project “StoreResponseValueInFile” on the project tree
2) Select “Add WSDL” from the menu that appears (Refer to the below screenshot for clarity)
3) Input the currency converter URL in the “Add WSDL” window
4) Click OK
5) Now, you will find the “StoreResponseValueInFile” project including the interface steps under the project tree. If you expand the web service (ConversionRate), you will see a default node named “Request1”.
6) Double-tap the “Request1” node to see the request XML content. Feel free to rename it if desired.
Creating Test Suites and Test Cases
- Right-click on the “CurrencyConvertorSoap” interface in the project tree
- Select the option “Generate Test Suite” from the popup menu
- Preserve the default settings and press OK
- Specity “SampleTestSuite” as the test suite name in the provided field and press OK
- The test suite “SampleTestSuite” is now created with a test case titled “ConversionRate TestCase”
- Right-click on the name of the test case and select “Rename” to modify it to “SampleTestCase”
Incorporating Groovy Steps
1) Go to the “sample test suite”, right-click on it, then hit the “sample test case” node
2) From the popped up menu, select “Add Step” → “Groovy Script” test step
3) Name the groovy script “GetResponseValue” and press OK
4) The groovy script test step will then be added to the test suite and you will be directed to the script editor
5) Enter the script as follows in the editor:
def response = context.expand( ‘${ConversionRate – Request 1#Response}’ )
new File( “D:/Groovy/” + “_response.txt” ).write( response )
Note: Ensure that you have run the “ConversionRate” request with the necessary input parameters.
6) Double-click “SampleTestSuite → SampleTestCase → TestSteps(2) → ConversionRate – Request1”
7) Hit on the “XML” tab in the side vertical bar
8) Substitute the question mark (?) in the SOAP code with the input data below:
- FromCurrency = USD
- ToCurrency = INR
9) Double-click on “SampleTestSuite → SampleTestCase → TestSteps(2) → GetResponseValue”
10) Click on the “Run” button to execute the TestSuite
With the completion of these steps, we have stored the response data on our local drive successfully. Verify the response in the response tab and on the hard drive to ensure they both match.
There is also a way to save the request details in a file, just follow these steps:
1) Right-click on the script editor, then click “Get Data” → “Step 1 [ConversionRate]” → “Property [Request]” (Refer to the below screenshot)
2) SoapUI Pro will give you code like this automatically:
def request = context.expand( ‘${ConversionRate#Request}’ )
3) Add the following script on the next line:
new File( “D:/groovy/” + “_request.txt” ).write( request )
By running this script, a file named “_request.txt” will be created in your local drive as mentioned in the script.
See the below for storing raw request through groovy scripting:
testCase.getTestStepByName(<teststep name>).getProperty(“Request”).getValue()
Or
context.testCase.getTestStepAt(<index>).getProperty(“Request”).getValue()
Or
testRunner.testCase.getTestStepAt(<index>).getProperty(“Request”).getValue()
These scripts can be used to secure the raw web service request while executing the test step. Following these scripts, we can append a line to store the request details in a variable, as shown in the code examples. Refer to the example below:
def request = testCase.getTestStepByName(“ConversionRate”).getProperty(“Request”).getValue()
new File( “D:/GroovyRequest/” + “RawRequestData.txt” ).write( request )
Conclusion
This not only concludes this tutorial but also puts an end to the complete SoapUI tutorial series. We hope you found it beneficial and that it helped boost your SoapUI skills. Remember that practice, patience, and perseverance are just as crucial as the tutorials themselves to attain optimal results.
As a final review of all that you have acquired in this SoapUI training series, we will be presenting a tutorial on SoapUI interview questions and answers.
We welcome your thoughts, experiences, and any questions you might have.
Thank you for joining us in this journey!