Monday, June 16, 2014

DataDriven Testing in SOAPUI Open Source WebService Test Tool using Excel File.


DataDriven testing is always comes first when evaluating any test automation tool, and other features depends on the needs for the project. And most of the Test Automation tools which supports DataDriven testing as paid tools I mean to say strictly Licensed, some of the tools are less in License price and some of them are very high, due to this reason all some of the test automation tools creators provides Open Source tools which are less in the features.

Now in this post I am going to describe some technique to DataDriven testing on SoapUI Open Source tool, in which there is no DataDriven feature present. Which helps you in saving License price. (After publishing this post one team will find me for sure, I Am Sorry Team).

So let us start, as you all know how to create project, Test Suite and Test Case (or refer my other post for the same).

In below screen you can see the Project Test Suite and Test Case created. In right pane, you can see the xml, which is actual request xml for the “SendSMSToIndia” request.













Also observe there are totally three fields are present in which we need to enter the data to it from the excel sheet.

        <web:MobileNumber>?</web:MobileNumber>
         <web:FromEmailAddress>?</web:FromEmailAddress>
         <web:Message>?</web:Message>

Now move on to preparing the Input data for the request fields from the excel file, to do that just follow the steps,

Open excel file and create header as same as the fields name, here in our test request we have fields name as above so here header is as below in excel file, ’MobileNumber’, ‘FromEmailAddress’ and ‘Message’.











Now it’s time to prepare the input excel file with required test data, may be Valid or invalid based on the project requirement. After successful update of the test data into the excel file, the file will looks like below.




















Now its time to add import this test data to the request xml by using Groovy script. Write Groovy/Java code to read the Excel file and use the SOAPUI inbuilt library functions and some groovy scripting function to read and assign value to the xml tag in the request xml.
   
To do so add Groovy Script to Test Step to the Test Suite, once you add then your request looks as below,






















Now write the Groovy/Java code to read the excel file data and Groovy. Refer the below screen shot for the code.


Once you done with the writing above code in your Groovy Script in the Test Step, then now its time to execute the Groovy script. When we run the Groovy script this script will read, excel sheet data and assigns the value to the xml respective xml tag in to the Request xml and run or execute the “SendSMSToIndia” request.

Now its time to read the Request’s Response xml. When we execute the “SendSMSToIndia” request then below response is returned by the system,












In the response xml we can see ‘FromEmailAddress’ ,’MobileNumber’, ’Provider’ ,’State’, and ’Status’ are the tags which need to verify in the response. For this need to below lines code to get value from response.







Keep these lines of code inside the for loop, why system reads the each row till last row of the excel sheet input data and assigns to respective tag of the request xml, and once the request executes then system generates the response xml then above code reads the respective or required tags from the response xml. Once you add above code to the Groovy script code then finally script looks like below.



In short Script will read the excel sheet data as cell value (row, column), this values is as same as tag name in the request xml.
Script will read completely content of the xml and stores in the holder. This holder will take above excel cell value to verify the tag is exist in the xml or not, if exist then enter the value and update the xml.
Script will also execute Request for each record in excel until the last row of excel.

Now you can use these parameters which you read from the response xml, and update into the excel sheet just as Report.

Once you done with this then you have saved some more budget to your organization, which you are spending on buying License every year.

 With this…

That’s all Folks.


Wednesday, April 9, 2014

DataBase Testing With SoapUI


Hi All this is my new post on SoapUI which describe about the Database testing in SoapUI tool, which is mainly helps in validating your SoapUI response and the actual value present in Database.
               In this post I will describe how to do Database testing like, how to get connection with Database from SoapUI tool.

Before starting Database testing we have to get connect to the Database from the SoapUI, so we can get connection to the Database in 3 types, here in this post I will describe all 3 types of connection with DataBase from SoapUI.

Type I:- Get Database connection at Project level, by just following below steps.
              
  As I described in my previous post how to create Project, Test Suite and Test Case. Create project and right click on the project you created or double click on it and follow the steps, open the Project View.



Once you select or clicked on ‘Show Project View’ you will see the below screen in the right pane of SoapUI window, and after that click on ‘JDBC Connections’





And you will be seeing JDBC Connection pane in which we have to create New Database Connection, now follow the steps marked in the screenshot, once you click on the “+” sign as marked new popup box open, enter the DB Connection Name, and click OK,



Once you entered the DB Name and Click OK, you will see the below popup where we need to enter database details as shown in the below screenshot 



Click ‘Test Connection’ button to test the Database Connection, once after you filled all correct value into it,  if all the details are correct you will see message as “The Connection Successfully Tested” means successfully connected to the Database.[Here I have selected the Driver as “Oracle Thin/Oracle Jdbc Odbc driver”] as shown in below screenshot,



The same DB Name can be used in the in your Test Case JDBC Request step.


Type II:- Here we will see how directly we get connection to the database from JDBC Request Test Step in the Test Case. Here you can see the above created, DB name you can use the same or you can create new one. Here how it is as shown in below steps.
Add your request to Test Case (Follow my previous post to create Test Case and add request to Test Case). Now add JDBC Request to the test step.


Once you added the JDBC Request to the Test Step, open that step by double clicking or right click and select ‘Open Editor’. Then JDBC Request window will look like below screen.


In above screenshot as you can see the DBConnect name as it was created in the in Type I.

Assume you have not created or not connected to Database at project level, and now you want to connect to the Database at Test Case level, then you can select or Click on “<Create New>” option, once you selected ‘Create New’ you will see below screenshot New JDBC Connection popup box here enter the DB name, here I have entered DB name as ‘NewDBConnect’


Once you Click ok you will see below window, in this you need to enter all the details to get connect to Database.


In above screen you can select any driver as per your need or as per your database, here I have selected Oracle Thin/JDBC driver. As shown in below screen.


Once you selected Driver, after that you need to provide all the details as Hostname, username, password, Port and SID and Click on Test Connection, if you get message as “The Connection Successfully Tested” means successfully connected to the Database. As shown in below screenshot.




Once you click on “OK” button you will see below message box asking for take out to the new window where you need to build the query or select the table or write your own query to retrieve the result. In below screen select ‘Yes’ button you will see the next screen where you will find all the table which are present in your database as per your user access.



Once you are satisfied with your query build and you got the expected result, then just click on OK button,


Now you will come back to same JDBC Request window, and you can also see the query which you built in above screen in JDBC Request. Once you execute this query you will see query result in XML format or in form format in JDBC Request right pane, as shown in below screenshot.



Type III:-
               Now we will see how to connect to Database from the Groovy script, just add the ‘Grooy Script’ test step to your test case as shown in below screen.



Once you added the Groovy Script to the test case, write connect string to connect to database as shown in the below screen.



Here, Type-I and Type-II difference is, In Type-I, we create DB connection at project level then can use the same DBConnect reference throughout the project and use that in JDBC Request. In Type-II its just related to that particular test case and you cannot use outside the test case. This type of connection useful when you have to use different database for each Test Case then this will help you.

I hope this will help you in your project for Database testing.
In next post I will post some useful sql queries to retrieve the data from table in Groovy script.


That’s all Folks.


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.