Monthly Archives: April 2014

SoapUI – Converting your functional tests into load tests

In the SoapUI – Getting Started we have seen how to create a functional test.

Now we are going to see how to do load tests for the API’s by reusing your functional tests that you have created.

Once you have created your functional tests, under TestCase tree, you will be having three child nodes.
one is test step where your functional test steps resides. Second is the Load Test node.

Right Cick on the Load Test Node and select “New Load Test”. This will automatically create the Load Tests Steps for you.


If you open the window, You can see some new terms or facts in the window. Lets see these facts one by one.

1. In the LoadTest tool bar buttons, you can see a Limit option by default sets to 60 seconds.
This is nothing but Setting the limit for the LoadTest Execution time.
2. Threads – Sets the number of threads/Virtual users to be used.
3. Strategy – Choose a LoadTest Strategy. Lets see this in detail. By default I will use Simple which means, TestCases will be executed within a configurable Test delay.
4. Test Delay – The time in milliseconds between each batch of requests.
5. Random – The random factor of the Test Load. This means by default the Test delay is 1000 ms and the random factor is 0.5.
So the threads will be distributed randomly between 500ms – 1000ms
6. min-The shortest response time the step has taken (in milliseconds).
7. max-The longest response time the step has taken (in milliseconds).
8. avg-The average response time for the test step (in milliseconds).
9. last-The last response time for the test step (in milliseconds).
10. cnt-The number of times the test step has been executed.
11. tps-The number of transactions per second for the test step.
12. bytes-The number of bytes processed by the test step.
13. bps-The bytes per second processed by the test step.
14. err-The number of assertion errors for the test step.
15. rat-Percentage of requests that failed

When clicking on the Run button, you can see the data/statistics for all the facts mentioned above.

Now we have also done performance tests for our API’s by re-using our existing functional tests.


Script Assertions in SoapUI

SoapUI uses XPath to manipulate XML. But we cannot use XPath expressions on JSON.
But soapUI have capability to convert JSON to XML.
Only difference is that instead of using Response property you have to use ResponseAsXml property.
ResponseAsXml in soapUI will convert JSON to XML.
The best and easy way to assert on a JSON response is to use a Groovy Script Assertion
Now lets see how to use Script Assertion on a JSON reponse.

"Token":    {
      "UserId": "",
      "TimeStamp": "31/12/2014",
      "SignedInAs": "test"

The following is the script we can use to assert the content of the above Json response

import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def json = slurper.parseText response
assert json.Token.UserId = ""
assert json.Token.TimeStamp == "31/12/2014"
assert json.Token.SignedInAs == "test"

Basic Assertions in SoapUI

1. Contains:
Search for the existence of a String in the Response Value. Applicable for JSON/XML reponses.


For Example if your response JSON is

"Success": true,
   "AUTH":    {
      "UserId": "linkeshkannavelu",
      "TimeStampUtc": "2014-04-22T07:25:05.0077957Z",
      "SignedAs": "4Rfc0/test/Vcpk="

and you are looking for the string linkeshkannavelu in the response, then you can enter the string in the Assertion Window.


2. XPath Match:
Traverse the XML response and return the value presents in the specific XML Node and then compares it with the expected value given.
Applicable only to property in XML Format.


For Example, in the last post we have verified the title of the site
If the returned response is

			<title>Keep Software Testing Weird</title>

You can check the title of the page by using the following Xpath.


3. Not Contains
Search for the non existence of a String in the Response Value. Applicable for JSON/XML reponses.


For Example if your response JSON is

"Success": true,
   "AUTH":    {
      "UserId": "linkeshkannavelu",
      "TimeStampUtc": "2014-04-22T07:25:05.0077957Z",
      "SignedAs": "4Rfc0/test/Vcpk="

and you are looking for the string TestUsername to be not present in the response, then you can enter the string in the Assertion Window.


If the String exists in the response, then the test will fail.

4. Valid HTTP Status Codes:
In the reponse, usually we will get a HTTP Status Code. We can assert these response codes also.


For example, if you are checking that your response message got the code HTTP Status 200, then you can assert the code by


5. Invalid HTTP Status Codes:
This is similar to Not Contains. If the HTTP Status Code that we are receiving Should not contain the list of Codes, then we can check those assertions using this.


For example, if you are checking that your response message should not have the code HTTP Status 401 and 404, then you can assert the response code by


These are the frequently used assertions in SoapUI.

SoapUI Getting Started

SoapUI is a free and open source cross-platform Functional Testing solution. With an easy-to-use graphical interface, and enterprise-class features,
SoapUI allows you to easily and rapidly create and execute automated functional, regression, compliance, and load tests.
Download SoapUI From
Install this by double clicking on the downloaded file and simply following the steps. Now Open SoapUI.

My First Project in SoapUI:
Today We are going to create first project in SoapUI by sending simple HTTP Requests and verifying the Response.

1. After Opening SoapUI, Goto File and Click “New Rest Project”


2. Enter the URL for the endpoint/Service that you are going to test and Click Ok. I have entered “;

3. This will create the “Rest Project 1” with the resource
Right Click and delete all the Child Resources under
4. Right Click the “Rest Project 1” and Select “New TestSuite”. Enter the name for the Test Suite as “MyTestSuite”


5. Right Click on the “MyTestSuite” and Select “New TestCase”. Enter the name for the Test Case as “TestCase1”


6. Under TestCase1, right click on “Test Steps(0)” and Select “Add Step” and Select “HTTP Test Request”.
7. Enter the Test Step Name and End Point and Give OK.


8. Look at the following figure. The Method is “GET” and requested URL is


9. Now we are going to hit the Request and Verify the expected result with the actual.
To do this. we are going to insert “Assertions” here.
10. At the bottom of the Test Request screen, Click on the “Assertions” and Click on the + SYmbol to add an assertion for this test request.
11. Select the type of assertion as “Property Content” in the LHS and Click “Xpath Match”.


12. Now we are going to Verify the title of the http response. Title of my site should be “Keep Software Testing Weird”


13. Hit the Submit Request button at the top of the Test Request screen and see the response in response window.
As the Xpath matches with the actual response, My Test Step should Go Green and the Xpath Match Assertion should also Go Green.
It means, the Expected Result “Keep Software Testing Weird” matched with the actuals.


Thats it. We Sent a request to a end point and got the required response and verified that.

Automate/Schedule the Database Back Up

Today we are going to see how to automate the backing up a database.
If we are frequently making changes in a database on a daily basis, then it is a good practice to backup the database
before making Changes. Instead of doing this manually, we can also automate the database backup task in MS-SQL Server.
It is very easy and very simple.

1. Open the SQL Server Management Studio. Connect to the database server. I have connected to localhost database server.
2. Expand the “Management” Option. Under that You can able to see an option called “Maintenance Plans”
3. Right Click on the Maintenance Plan and Select “New Maintenance Plan”


4. Enter the Name for the Maintenance Plan. I have given name as “AutoBackup-AdventureWorksDB” and Give Ok.
This will navigate you to the design page of that plan.


5. Enter Description as “To Automate the Database Backup on a daily basis”
6. For Scheduling this job, Click on the Calendar Like icon on the SubPlan Schedule Column.


7. This will open the “Job Schedule Properties” window. Select the “Frequency Occurs” as “Daily”. Leave remaining things as it is.


8. If you are backing up a database in your local machine, give the time as “12:00:00 PM”. When the job runs during that time, the machine/server should not be shut down/switched off.
9. Give Ok. Now Click on the Toolbox tab in the “Design” Page and Double Click “Backup Database Task”


10. This will create the “Back Up Database Task” in the Design page.


11. Double Click on the “Back Up Database Task” in the Design Page and this will open the “Back up Database Task” window.


12. If you are backing up the database in local, then leave the connection as “Local Server Connection”
Or Click on the New button and select the Server. Leave Backup type as “FULL”
Select the Database that you want to backup. I have selected “Adventureworks2008R2” database.



13. Enter the Directory for the Database backup. I have given as “D:\SQL DB\BACKUP”. Leave remaining settings as it is and give Ok.


14. Click on “Save” or press “Ctrl+S”.

Thats it. Now you have successfully automated the backup of “AdventureWorks” database.
Now this job will run daily on “12:00:00 PM” and it will create a backup [.bak] file in “D:\SQL DB\BACKUP” directory.


Cursors in SQL Server and its Usage:

In SQL Server, we can use While loop to iterate using a Variable. But if we want to iterate through the rows of a result set, we can go for Cursors.
So Cursors is a mechanism to explicitly enumerate through the rows of a result set, rather than retrieving it as it is.
Syntax of a Cursor is,

 WHILE (@@Fetch_Status = 0)
   [Do Manipulation for every Row Here]

Now we are going to see an example for CURSOR with better usage:
Consider this scenario. I have a 17 tables in my database with similar name %TenantSummary% like
1. AppTenantSummary
2. ClientTenantSummary
3. RowTenantSummary
17. DataTenantSummary

I want to insert similar set of values in all these 17 tables. For this, We can create individual Insert statements.
But I am going to simplify this by Creating a Cursor that will insert similar set of values in all these 17 tables.

Following is the code that will insert similar set of values in all the TenantSummary tables.

DECLARE @TableName varchar(200)
DECLARE @Query varchar(Max)

 SELECT '[' + + '].[' + + ']' FROM sys.tables
 INNER JOIN sys.schemas ON schemas.schema_id = tables.schema_id WHERE tables.Name LIKE '%TenantSummary'
 OPEN TenantSummary
 FETCH NEXT FROM TenantSummary into @TableName
 WHILE (@@Fetch_Status = 0)
   SET @Query = 'INSERT INTO ' + @TableName + ' SELECT ID, Name, 1 FROM Master WHERE ID LIKE ''%DTS%'' GROUP BY ID '
   PRINT @Query
   FETCH NEXT FROM TenantSummary into @TableName
CLOSE TenantSummary
DEALLOCATE TenantSummary

But always there is a saying that Cursors will cause severe Performance issues in SQL. So limit the usage
of Cursors. But for QA, if we are not bothered about some extra seconds of execution for SQL Queries, We can do magics using Cursors in SQL.

Restore/Create Database using a database backup in SQL Query

Restore/Create SQL Server Database from a DB BackUp using SQL Query:
1. Connect to the database server in sql server management studio. For example localhost. Right Click on the “Databases” and Choose “Restore Database” option. This will open the “Restore Database” window
2. To extract the query required to restore/Create the database, Click the Script button on the top and select “Script Action to New Query Window”



3. This will give you the query to restore a database using an existing backup.

Below mentioned is the Query to create new database “TEST” from the database backup in the “D:\SQL DB\BACKUP\AdventureWorks2008R2.bak” path in device.

FROM DISK = N'D:\SQL DB\BACKUP\AdventureWorks2008R2.bak' 
MOVE N'AdventureWorks2008R2_Data' 
MOVE N'AdventureWorks2008R2_Log' 
STATS = 10

You may also change the path of the .mdf and .ldf files if you want. By changing the .mdf and .ldf files, will create the database in a different location that you have specified.

Restore SQL Server DataBase from a Backup

Now we are going to see how to restore a database backup in MS-Sql Server using management studio.

1. Connect to the database server in sql server management studio. For example localhost. Right Click on the “Databases” and Choose “Restore Database” option


2. This will Open the restore database window. Enter the name of the database that you want to create in the “To Database” Field. Here I have entered my database name as “TEST”


3. Choose the option “From Device” and click on the browse button.Now locate the backup file “.bak” file and give Ok.


4. This will navigate you to “Specify Backup” directory. where your backup file will be specified. You can remove that file here bu remove button and add the new database backup file using “add” button.


5. Give “OK” in the “Specify Backup” window. This will navigate you to the “Restore Database” screen and select the “Restore” check box in that window.



6. Click on the Options page and there you may specify the path for your database to be created. 


7. Again Goto “General” Page and Click the Ok button.


8. You can see the progress the the Left side bottom in % and once the restore is complete you should get a prompt as 



Thats it. Now the new database “TEST” has been created and you can play with it.