Wednesday, October 30, 2013

Keyword Driven Framework - (Operational Level)

Keyword Driven Framework - (Operational Level)

You have already seen Keyword Driven Framework at higher level. Here and in the next two posts we are looking into Keyword Driven Framework at operational level (lower level). In this post we have Keyword Driven Framework where both data and keywords are in one file, next we will look into Keyword Driven Framework where data and keywords are in separate files and later a Keyword Driven Framework which is web based with separate data and keywords file.

Instead of giving you the option to straightaway download and try these, it would be better if you try to build this framework yourself from scratch. That way you will be able to grasp it more easily and in depth.

Below is the folder structure:



There are three parts to this framework:

1. UFT Test (UFT_Test_Cases),



2. Function Library (Function_Library)

Variable declaration in Function Library:


Function 1 in Function Library


Function 2 in Function Library


Function 3 in Function Library


3. An Excel Sheet (Keywords) [because of space limitations the complete screenshot is divided into two parts]



What this framework does:

This framework inserts a new order in the Flights application.

In order to run this framework you have to fulfill the prerequisites as below:

1. In the Excel file you have to change some of the data. Firstly make sure if the path to the flight4a.exe is correct. Secondly the date (060614) should be correct e.g. enter some future date and thirdly along with date, also change the flight information (11820 LON 06:15 PM PAR 07:55 PM NW $138.60) accordingly. Below only last two columns of an excel are shown:



2. Make sure that variable "Excel_Location_Path" (see screenshot under "Variable declaration in Function Library") in Function Library correctly points to the data (read Keywords.xls in the folder structure above) file.

3. When you open the test (UFT_Test_Cases), you must associate the Function Library (Function_Library) with the test.

    File (Menu) -> Settings.

In the Test Settings dialog that opens, go to Resources and associate the Function Library.

Now try to Run this framework.

Explanation of the above framework:

UFT Test is calling the first function in Function Library i.e. func_Read_Excel. Function func_Read_Excel is importing the Excel data into QTP / UFT DataTable. Each column of a row (in DataTable) is being read in the different variable and then function func_Establish_Hierarchy is being called from there.

func_Establish_Hierarchy is creating a hierarchy of objects using Set statement. For example

Set ObjectVar = ObjectHierarchy

In the example below, the Set statement specifies the variable Temp_EditBox to store the full Browser.Page.WebEdit object hierarchy for the ‘username’ edit box. The Set method then enters the value “Prince” into the ‘username’ edit box, using the Temp_EditBox variable:

Set Temp_EditBox = Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username")
Temp_EditBox.Set "Prince" 

In function func_Establish_Hierarchy we are also using Description object like below:

Set child_object = Description.Create()
 child_object("micclass").value = sControl_Name
 child_object(arrControl_NameProp(0)).value = arrControl_NameProp(1)

These above 3 lines can also be written as below in order to have more clarity (Control_Property of second row of excel sheet (Keywords.xls) is being used here):

Set child_object = Description.Create()
 child_object("micclass").value = WinEdit
 child_object(Attached Text).value = AgentName

At last Execute_Action() function is called and based on the value of sAction_to_Perform's variable, appropriate action (Run, Type, SetValue etc.) is called.

In a nutshell, the functions in the Function Library are using the keywords in the keywords file in order to perform actions. These functions pick the keywords (one row at a time), build hierarchy and perform actions (Run, Click etc.) associated with the hierarchy. The data to be used with the action is specified in the Data column of the Keywords.