QTP – Parameterization with Data Table

by seetaram on October 15, 2011

When a test is recorded using QTPs recording engine all the values are hardcoded. If we want to run the same test many times, the application might throw error because of duplication of data. Hence, the data needs to be parameterized from an external means.

QTP provides an excellent feature called Data Table for this purpose.

To demonstrate this feature, let us take an example of Flight sample application.

Create a new test as below:

  • Record “Insert New Order Scenario” (Refer – Insert New Order)
  • Replace the From with Origination parameter
  • Replace the To with Destination parameter
  • Replace the Name with CustomerName parameter

Open Data Table: Click View –> Data Table

Double click first column header “A” and change the name to CustomerName

Double click second column header “B” and change the name to Origination

Double click third column header “C” and change the name to Destination

Now we have three parameters in the data table. We just need to insert the values in all the three columns

Karthik    Denver          Frankfurt
Sam        Frankfurt       London
Rajini     London          Denver
Ranjana    Los Angeles     Portland
Vinay      Paris           San Francisco
Siva       Portland        Los Angeles
Vikram     San Francisco   Paris
Rajesh     Seattle         Zurich
Vikram     Sydney          Seattle
Rekha      Zurich          Sydney

Save the Test as “InsertOrderParameterization

Below is the code snippet for the test:

'Script  - "Insert New Order" in the Flight application 
'CustomerName, Origination, and Destination are parameterized through DataTable
' Purpose - Demonstrates Parameterization
'Author - Seetaram Hegde
'Copyrights - All rights reserved

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "admin"
Dialog("Login").WinEdit("Password:").SetSecure Crypt.Encrypt("mercury")
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").ActiveX("MaskEdBox").Type "121212"
Window("Flight Reservation").WinComboBox("Fly From:").Select Datatable.Value("Origination","Global")
Window("Flight Reservation").WinComboBox("Fly To:").Select Datatable.Value("Destination","Global")
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set Datatable.Value("CustomerName","Global")
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").ActiveX("Threed Panel Control").Check CheckPoint("Threed Panel Control")
Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

As we can see in the above code,

Replace the value in “WinComboBox("Fly From:").Select "Denver"” with “Datatable.Value("Origination","Global") ”

Replace the value in “WinComboBox("Fly To:").Select "Frankfurt"” with “Datatable.Value("Destination","Global")”

Replace the value in “WinEdit("Name:").Set "Karthik"” with “Datatable.Value("CustomerName","Global")”

Save the test.

We also need to set the Run options to “Run on all rows” by,

Click File –> Settings –> Run –> Select Run on all rows

FileSettings

TestSettings

The above setting will tell the QTP to run the test for multiple sets of test data.

Since there are 10 sets of data stored in the Data Table of the test, the Test Script will run for 10 iterations and we can get the result for all the iterations.

Execute the test now with F5 or Run.

Evaluate the result once execution is over.

ParameterizationResult

The above figure shows the result of the test after execution, which contains the status of all the iterations (from 1-10).

The Test Scenario Script what we have created just now demonstrates how we can utilize the Data Table feature of the QTP (QuickTest Professional) to run a test against multiple sets of Test Data.

{ 7 comments… read them below or add one }

QTP Best Practices August 27, 2012 at 11:54 am

Very good example for Data Table Concept 🙂

Reply

satish April 15, 2013 at 1:36 pm

Title:parameterization with data table
Eg:flight resarvation
in datatable we can give the different inputs
eg:agentname password these are columns.
in side of datatable for the first time(1) eg:satish,mercury the test was passed.
for the second time(2):eg:satish,merc the test was failed
for the second time(2):eg:sat,mercury the test was failed
the (2&3)time test was failed.
how to solve this type of problem.

Reply

Tester December 20, 2013 at 5:34 am

Hello Satish,
In the flight application, Username should have 4 or more characters, so your 3rd test fails. And password is set to mercury only, so your 2nd test also fails.

Reply

santhosh October 25, 2013 at 3:34 pm

Gr8 work …Really helps beginners to learn …gud job!!!

Reply

Keyur Makwana November 7, 2013 at 9:11 am

Its give me an error “The “Threed Panel Control” ActiveX object was not found in the Object Repository. Check the Object Repository to confirm that the object exists or to find the correct name for the object.”

Reply

Tester December 20, 2013 at 5:30 am

Hello,
Nice example, but I wanted to ask, according to this, the application will close after each iteration. But if we want that next iteration should run just after previous order is placed, without closing the application, then how it is done?
Thanx

Reply

seetaram January 10, 2014 at 6:59 am

Example should only be used for learning purpose. After learning, you should start applying your own logic to accomplish automation of test cases.

Reply

Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email