Parametrization In QTP

Parametrization is mainly useful when the functionality is tested with different sets/ types of data. This is mainly used in Data Driven Testing.

We have different ways to parametrize the tests.

Loop Statements: We can use the loop statements for passing sequential numbers and Logical Numbers.
Assume that we are going to enter numbers in a sequential manner in a text box.
Example: Flight Application
 
For i=0 to 20
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.').Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i
Window("Flight Reservation").Dialog("Open Order").WinButton("OK').click
Next

We need to remember that strings can't be generated through Loop Statements. But the same can be achieved with the help of Dynamic Data Submission.

Dynamic Test Data Submission:
We can pass the strings thought loop statements. But the user interaction is required.

Example:
For i=0 to 20
uName=inputbox("Enter User Name:")
pwd = inputbox("Enter Password:")
'Use the following snippet
Dialog("Login').WinEdit("UserName").Set uName
Dialog("Login').WinEdit("UserName").Type micTab
Dialog("Login').WinEdit("Password").SetSecure pwd
Dialog("Login').WinEdit("Password").Type micTab
Next
 
Data Table:
As we know that QTP uses one data table for every test. We have the following types when using Data Table for parametrization.

01.Entering test data directly to data  table and use.
02.Importing test data from external spread sheets.
03.Importing test data from external flat files.

Entering Test Data Directly to Data Table and Use:
We need to follow the below mentioned steps when entering and using Test Data directly to Data Table.

01. Generate Test > Open Data Table
Note: The Data Table can be opened by navigating to View> Data Table
02.Click on the column header> Enter the name of the field(Ex:UserName)> Enter Data> Connect data to Test by using the following code snippet.

variable=datatable("column name",sheet id)
Ex: uName = datatable("UserName",1)
03.Run the test

Example:
uName= DataTable("UserName',1)
pwd = DataTable("Password",1)

Importing Test Data From External Spread Sheets:
We have to follow the below mentioned steps when using spread sheets for parametrization.
01. Open Data Table> Place the mouse pointer on Data Table and right click> File> Import From File>Click Ok>Browse the path of the excel sheet.
02.Then connect the data sheet to test by using the code snippet "
variable=datatable("column name",sheet id).
03.Execute the test.

Importing Test Data From External Files:
We can also import the data from external flat files by following the below mentioned steps.
01. Open Data Table> Place the mouse pointer on Data Table and right click> File> Import From File>Click Ok>Browse the path of the file sheet.
02.Then connect the data sheet to test
03.Execute the test.
Example:
Dim fso,ffile
Set fso=CreateObject("Scripting.FileSystemObject")
Set ffile = fso.opentextfile("D:\Automation\test.txt",1)
ffile.skipline
While ffile.atendofline<>true
a=ffile.readline
b=split(a,"@")
'Write code to launch application here...
'The following snippet is to set the data read from the file to 'variable.
Dialog("Login").WinEdit("UserName").Set b(0)
Dialog("Login").WinEdit("UserName").Type micTab
Dialog("Login").WinEdit("Password").SetSecure b(1)
Dialog("Login").WinEdit("Password").Type micTab

Apart from the above methods we can fetch the data directly from the database as well as we can use the Dictionary object for parametrization.

Using Dictionary Object:

Set inputdata= CreateObject("Scripting.Dictionary")
inputdata.add "Username", "stc"
inputdata.add "pwd", "hp123"
'Write code to launch application here...
'The following snippet is to set the data read from the file to 'variable.
Dialog("Login").WinEdit("UserName").Set inputdata("Username")
Dialog("Login").WinEdit("UserName").Set inputdata("pwd")
SHARE

About அமரகோசம்

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment