Thursday, December 26, 2013

Basics of WebService Testing Tool SoapUI


Hi, In this post I am going describe some basics of SoapUI tool, like Creating projects, Creating Test Suite and Test Cases and Some important features.

Let’s Start with creating Project.

Create Project :-

To create project we need to have WebService WSDL file or the WebService Link. Here I will refer WeatherForecastService webservice and below is the link.



Now go to SoapUI there you can see in left pane as Projects, Here we are creating new project so Right Click on it and select “New SOAP Projects”. As shown in the below screenshot.




Once you click on this menu option you will see one window popups with two fields, as ‘Project Name’ and ‘Initial WSDL’. You Can enter Project Name as per your requirement or you can keep this field blank also when you browse for the WSDL or service link, then automatically Project Name appears. Initial field click on the Browse button to locate the WSDL file stored in your system or enter the service link. Once you provided the WSDL or Service link the window looks as below. (Here I have provided “WeatherForecastService” service link).


As you can see project name as “WeatherForecastService”. Keep below three fields as it is and click on OK button. Now you are done with project creation. And your project in SoapUI Looks as in below Screenshot.




In Above screen shot you can see the WeatherForecastService has two Request or say Operations. One is ‘GetCitiesByCountry and another one is ‘GetForecastByCity’.


Now we are done with Project creation, now will move on to Creating Test Suite.

Create Test Suite & Test Case :-

Creating Test Suite is very simple; just follow the few steps as mentioned in below screenshots.
When we created Project for WeatherForecastService we have noticed there are two Requests, now we will create Test Suite for ‘GetCitiesByCountry’ request.

Click on the (+) sign to expand the Request, there you will see soap request as “Request 1




Now Right Click on the ‘Request 1’ and Click on Add to Test Case




Once you select you will see a popup asks for the Test Suite name and Test Case Name, There you can enter any custom name as per your requirements, and enter the Test Case name also as below.


Here I have provided Test Suite name as “GetCitiesByCountry_TestSuite”.


Here I have provided Test Case name as “GetCitiesByCountry_TestCase”.



Once you entered both Test Suite Name and Test Case Name, you will see the one more popup window which contains GetCitiesByCountry Request name in it just click OK button to complete the Test Suite and Test Case Creation.



After Click OK button the finally Test Suite contains Test Case look as below.



Now we are done with the Project, Test Suite and Test Case creation. Now I am going to tell you how to create or Add Test Steps to our Test Case.



To Add Test Steps as per your requirement, Just Right Click on the “Test Steps (1)” Click on ‘Add Step’ and select which step you want add, as below screenshot.






That’s all Folks.

Sunday, October 6, 2013

How to Add or Delete/Comment xml node or tag in SoapUI Request at Runtime


This is my new post after long gap, sorry for that. I am going to post this topic as everyone need this as I faced so many trouble while doing adding deleting or commenting tags ,I hope this will surely help you.

Here I go….

Add Tag:-

Staring with Add tag or node, to the SoapUI request xml. This case only works when the tag which you want to add should be present in “XSD” or say WSDL file, by chance you deleted tag and you want to add the same in request at runtime then this will help you.

As you all know SoapUI tool provide so many features for testing webservice, in that one of the outermost feature is Datasource, which helps us to do Datadriven testing, as I mentioned in my previous post same one.
Consider your wsdl file has below xml content (this is just for example).

Here I am using WeatherForecastService for my post purpose


(My sincere thanks to restful services)


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.restfulwebservices.net/ServiceContracts/2008/01">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:GetCitiesByCountry>
         <!--Optional:-->
         <ns:Country>India</ns:Country>
      </ns:GetCitiesByCountry>
   </soapenv:Body>
</soapenv:Envelope>

Considering above request xml, I want to add “City” after the “Country” node. (But make sure this only works when the City field present in XSD or WSDL file.)
To test the above service you have created some testdata as below




 In above screenshot as you can see SI.No 1 to 4 you want to add city tag and its values, in 5 case if you don’t want to enter any value in City tag so you have keep it blank, so I have used CityTagBlank column.

Now move on to SoapUI import your test data into SoapUI DataSource and follow the steps as below.
Step 1 :-
Once After importing the test data into DataSource, now go to your request, if your using SoapUI Pro version you will 4 tabs in request as ‘Form’, ‘Outline’, ‘Raw’ and ‘XML’. Click on XML tab you will see xml tags, in the xml file you can see “<ns:Country>” tag. Just after this tag Right Click and Click on GetData sele ct ‘Step1 DataSource’ and Click on Property CityTagOpen.


After selecting above property from Datasource do it same process for CityTagClose and CityTagBlank

Once done all your xml will look like same as below.



Just now you have created the dynamic tag in your request xml, now you have to provide the data into this tag, so now click or place cursor at between as shown below 


Once you place the cursor Right Click and select the City property from DataSource as shown in below screen shot.


Just now you have provided the value to the your newly created dynamic city xml tag it will look like as below,



Now you all set to run the request for all your test data.


Once you run this you will see your request xml look same as below.


In the above screenshot as you can see we have provided the dynamic tag and value as “Delhi” remember, above we have created the test data. The same value populated in “City” Tag.
Now we will see what value for second test case.


See above screenshot in second test case we have provided “Mumbai” as value for City tag.
Now time to see for Blank value in City tag how it will look like.




Remember in above test data for test case number 5 we have not set any value hence the “City” tag is balnk as per XSD schema.
Now we are done with adding the dynamic tag to the request at run time.

NOTE :-  This will work only when the tag is defined in the xsd schema otherwise it will not work.


Commenting  Tag:-

   Now we know how to add node at run time. Now it’s time to do reverse. You may this issue so many time while doing WebService testing as commenting or deleting the tags which is not necessary. For that my post will surely help you,

Let’s consider “GetForecastByCity” sample 

WebService(http://www.restfulwebservices.net/wcf/WeatherForecastService.svc?wsdl) in this request you will find two fields as “City” and “Country”. In test case where you want to comment the “City” or “Country” tag based on your test cases.

I have prepared some sample test cases where I am commenting tags based on my test data as below.


Here in above screenshot test case from 1 and 2 am I commenting “City” tag and for test case 4 and 5 I am commenting “Country” tag.

Import this test data into SoapUI DataSource, as described in my previous post. It will look like as below.


Now go to your request and click on the XML tab there you will see xml tags as below


Here I am going to insert the DataSource property for commenting the tags according to my tets cases at run time.
Put cursor in between <ns:GetForecastByCity> and <ns:City>, Right click and click on Get Data, select Datasource and click on “CityTagOpen” Datasource property as shown in blow screenshot.


And now put the cursor in between <ns:City> and <ns:Country> again Right click and got to GetData select DataSource and click on “CityTagClose” property.


Repeat the same process for Country, put the cursor after the “${DataSource#CityTagClose}”  property and in between <ns:City> and <ns:Country> again Right click and got to GetData select DataSource and click on “CountryTagOpen” property.



Now put cursor in between </ns:Country> and </ns:GetForecastByCity> Repeat the same same process to select the “CityTagClose” property from DataSource.


After all property set your xml will looks like


Above screenshot shows all xml tag open and tag close property set now, these property will read the value from DataSource and inserts actual value.

In above screenshot I have manually entered the value for City and Country, now I am going to insert these values also from datasource(mapping the datasource property to the field I have explained clearly in my previous post),  now the xml will look like below.



This is how actual xml looks like.

Now we all set to execute the request. When you run the request you will see the City tag and Country Tag will be commented as per test cases.

Here is sample how the xml will look after execution.
For test case 1 and 2 I have commented the City tag the same you can see in xml at run time.

Test Case 1


Test Case 2


And for test case 3 and 4 I have commented Country tag see below screenshot for Country tag commented at run time.


Now we all are done with Adding or Deleting/Commenting the soap request xml tags at run time.

Happy WebService Testing……


That’s all Folks.


Monday, May 20, 2013

Custom Report Generation from Data Sink in SoapUI Pro



As most of you all know report plays major role in any of the project, as business giant he don’t dig into and look he just look for end result i.e. Report. To generate the Excel report from SoapUI you need to just follow the below steps as i mentioned.
Create Test Data for SendSMSToIndia request as follows.  [Here I have taken SendSMS WebServices for example. (http://www.webservicex.net/SendSMS.asmx?WSDL)]
As all of you know how to do Data Driven testing as i mentioned in my previous blog. In the same way you have to create Test data in excel file.
Once you are ready with Test Data creation, then create one more excel file as follows for DataSink Report.
Here I have created the sample Report format as shown in the below screen shot. I have given Sheet name as “SendSMSReport” and saved it in the local system Driver with the name as Report_SendSMSToIndia.xls, here one more important note is while saving the excel file after creating the test data we should save as “.xls”and SoapUI is not support any other format other than .xls.


Now it’s time to create SoapUI project in SoapUI Pro tool as shown in below,

Make sure you have created the project and added the Request to Test Suite, to Test Case, to Test Step and DataSource, DataSink, Groovy Script and DataSource Loop should be as shown in below screen shots.
Now add Data Sink to the Test Step as shown in the below screenshot. To add Right Click on the Test Step and Select Add Step then select DataSink option.

























Now the DataSink step will be added to your Test Step as show in below Screen Shot.






















In the same way Add Groovy Step to the Test Steps which is used to validate or verify our expected result with actual result and same result can be used to update in DataSink.




















In below screen shot you can see the hierarchy of the Test Steps, make sure in your project should be in the same hierarchy as same as below.























DataSource:- Is Use to reads test data from external source(Excel, File, GRID, XML, Database) into properties of request or can be used for validation.
DataSource Loop:- Is Use to loop or iterate the DataSource till the last row. Here we have select the DataSource and target step where we have to provide our input data.[will be explain in below section].
DataSink:- Is used to write Number of propertied to the External source.
GroovyScript:- Is used to write specific script for validation.


Now Open the DataSink by double clicking on it or just Right click and select open editor you will see below DataSink editor. There you can see DataSink with Dropdown list in the screenshot.














Now click on the Dropdown button. You will see list of Option to generate the report in different format.













In that select Excel Option from the list to generate the report in the Excel format as you created the sample format above. Once you select the Excel option you will see below screenshot.













In above Screenshot you can see File, Out File, Worksheet and Start at Cell with (Re)Generate Properties with One green button. Here all the fields are explained below.
File :- This is the file where which imports the sample format which we created above.
Out File :- This file is used to Update our results or reports from Datasink and stores into the  specified file at under given path.
Worksheet :- The worksheet name of the file to export the result
Start at Cell :- From which Cell you want to export the result.
Change the Option Start at Cell Default value from ‘A1’ to ‘A2’ because in our excel sheet cell A1 is our headings and our actual report updates starts from cell A2 hence it should be A2.

Now To import al the headers which are created in excel file to DataSink properties click on the browse button locate the Excel file path which you created above, do it same for File and Out File, once you located you will see as same as below screenshot.
















Now click on the ‘Green’ button   (Re)Generate Properties:. Once you click on this button you will one more popup window named ‘Manage properties’ as shown in below screenshot.


















In the Insert row number: enter value as 1(one) because in our excel file we have just created on row that too header so we have to give as 1 only. Now click on ‘OK’ button.
Now you will see in DataSink left pane editor all the headers we have created in the excel file are automatically created see below screen shot for more.

















And also see the same property names are displaying in the below section in above screenshot.
Now Open the Groovy Script by double clicking on it or just Right click and select open editor you will see below Groovy Script editor. Here you can retrieve the data from any of the test step within the Test Case or from Projects and also from Other Test Suite and Test Cases with some limitations we will discuss this topic later.

Now follow the steps below to retrieve the data or result or value from the DataSource, From Response received for request.

Step 1:- Right Click on the Groovy Script Editor,
Step 2:- Goto Get Data click on DataSource select the property name which you want to compare with the actual result, here i am comparing the Actual and expected Status of the message.
















Once you select the Expected_Status property then you will see one popup as below, click ok or you can provide your own name or just click ok.

Then SoapUI will generate code for as in below screen shot.



Now select the value from the response as you selected property value for DataSource.

Follow the steps..
Again right click on the Groovy Script editor as shown in below screenshot and goto 
“SendSMSToIndia - Request” click on it and click on Property[Response]. 

















Now will see one more Select XPath window there you can see response which has all the fields, in that select the required field and click on OK.


































Then you will see popup as shown in below screen shot click on, then SoapUI will generate code for you as shown in below screenshot,















Now write ‘IF.. Else’ condition to compare the two Actual and expected status value. If you know java little bit then you can write it, for those who don’t know here it is.










Now moving to Data Sink above you have created Data Sink step and also added excel report 
format. Now associate the values from Data Source, from Response or from Groovy Script result.
Follow the steps below,
Open the Data Sink editor you can at right hand side of the pane four properties as
TC.No :- The test case number we are taking it from the DataSource step property name ‘TC.No’
Expected Result :- Expected Result we are taking it from the DataSource step property name 
‘Expected_Status’
Actual Result :- Actual result we are taking from the Step ‘SendSMSToIndia - Request 1’ as we 
taken value in Groovy Script in same way.
Test Result :- Test result we are taking it from the Groovy Script result.

For more detailed follow the steps,
For TC.No = Right click and follow the Screen shot.

















For Expected Result = Right click and follow the Screen shot.

















For Actual Result = Right click and follow the Screen shot.






















Click OK once you selected the required field.

For Test Result = Right click and follow the Screen shot.




















Now all set to run the Test Case for all the test data in the DataSource to generate the Report in excel format. Running the Test case you have to open the Test Case Running window you can double click on the Test Case or Right click and select ‘Show Test Case Editor’ option from the menu.






















And one more important note is the steps in the Test Steps should be in the same arrangement. Like DataSource should be at first Step and Request in Second, Groovy Script and Data Sink and DataSource Loop should be always last.

To Run the Test Case Click on the ‘Green’ buttonat the left top Corner of the Test Case pane.

Once execution start you can see the logs in Test Case Log pane ate below and a gree bar with “Finished”message at the top indicates test case execution completed for the all the rows in the DataSource and also Report is also generated in the path specified for Outfile.



The report will be looks like as below Screenshot.
















Now you are ready with custom report.


That’s all Folks.