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.
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 )
What You Will Learn:
Storing Request and Response in a File:
We will start from creating SOAP project:
- Open SoapUI Pro
- In the Navigator panel, right click on the Project
- From the context menu, click on New SOAP Project option.(You can also use Ctrl+N)
- New SOAP Project dialogue appears on the screen.
- In the New SOAP Project window, enter the project name, StoreResponseValueInFile.
- click OK
- 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.
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
- In the project tree, right-click on the CurrencyConvertorSoap interface.
- From the popup menu, click the Generate Test Suite option.
- Leave the default settings in and click OK.
- Enter the test suite name in the given text field, SampleTestSuite, and click OK.
- Now test suite is created along with the test case name, ConversionRate TestCase.
- 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.
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()
Or
context.testCase.getTestStepAt(<index>).getProperty(“Request”).getValue()
Or
testRunner.testCase.getTestStepAt(<index>).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 )
Conclusion
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!