Pages

Tuesday, December 28, 2010

Running loop requests using SaopUI

One of my friends told me a story about a guy who earns more than $300 dollars per hour with his expertise in the Microsoft Excel. It was little surprising for me, but when we think about it, to give something really quick and meaningful with what we have is really important rather than saying , If we had this and that we would have provided that etc etc. This we week we had a quick requirement to get data from a  secured we service. It was very urgent for the business unit to solve some discrepancy in reporting with the client.Basically we need to hit a webservice and take a value from the response, 1000 times.something like  a data driven load test.

Somehow , SoapUI came in to my mind and started experimenting it and found out that soapUI pro has the features which will be beneficial to us. Here is the experiment.

Needs:
1. We should be able to parametrize a value in the request (say customer Id), reading a value from an external file.
2. Read one field value from the response(say account balance) and write to a file against the input value.
3. We should be able to issue the request in a loop(same as the number of customer ids in the external file)


Solution:

Step 1:
Create a new project giving the WSDL location. Identify the request, right click  and click on "Add to TestCase". It will automatically create a test suit for you.

Fig: 1  

Now the project will look like Fig 1.

Step 2:

Now we need to think about  our needs . We should be able to read a value from the file . To achieve that SoapUI has a concept called DataSource. We should be able add another test step for this. Right click on testStep, click on add Step , and choose DataSource.

Fig : 2

Now you can see a new step is added to the test case:

Fig : 3
 But  the DataSource step should happen before the stockPurchaseRequest step , so move it one step above.
Now double click on the DataSource and the editor opens on the right panel.
Fig : 4   
Now create a new property (say customerId) and  then choose the appropriate DataSource( see Fig : 4)

Step 3: 
Now we have to hook this property to the request . In order to do that, double click the request, the editor open up on the right panel then  click on the Form tab. Choose the request parameter you want to get  from the DataSource. Click on the "Get Data" and choose it from the DataSource property.(See Fig : 5)

Fig : 5

Step 4:

Now we need to add a DataSink  which is the file where we store the values from the response. It is similar to the DataSource  creation. Add a new property (say PaymentType). Then choose the DataSink file location and type


Fig : 6

 Now we need to tranfer the response values to the DataSink. For that execute the request and get the response. change the response editor to "Outline" . Right click on the filed which you want to export. Click on "Transfer To" and point it to the DataSink property we created in the previous step.

Fig : 7
It will automatically create a PropertyTransfer step for you.

Fig : 8
Step 5:

Now finally we need run these step for each value in the DataSource. Add and configure a DataSource Loop step in to the Test Steps.


Now we are done with all the set ups. Add some value to the Data Source and run the test case . It will run as many times the data rows in the DataSource. It will create a new  DataSink file at the configured location.

One important thing to be noticed is that we can transfer any number of parameters  from the Data Source to request and from response to Data Sink as well.
Related Posts Plugin for WordPress, Blogger...