QTP – Parameterization with Data Table

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.

Comments 7

  • Very good example for Data Table Concept 🙂

  • 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.

    • 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.

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

  • 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.”

  • 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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.