Wednesday, October 30, 2013

Keyword Driven Framework - Operational (Data & Keywords are in separate files)

Keyword Driven Framework - Operational (Data & Keywords are in separate files)

Previously you have seen Keyword Driven Framework where data and keywords were in same file. Here we will look into Keyword Driven Framework where they are in separate files.

Below is the folder structure:

As said above, here we have separated the data from keywords and have entered the data in a separate (Data.xls) file.

There are four 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].

4. An ExcelSheet (Data).

What this framework does:

This framework inserts two new orders (namely First Order and Second Order as can be seen in the Data Excel sheet) in the Flights application.

Let’s try to run the framework. In order to run this framework you have to fulfill the prerequisites as below:

1. In the Excel file (Data.xls) you have to change some of the data. Firstly make sure if the path to the flight4a.exe is correct [e.g. the path D:\HP….in below screenshot]. Secondly the date should be correct e.g. enter some future date and thirdly along with date, also change the flight information (for example 11820 LON 06:15 PM PAR 07:55 PM NW $138.60) accordingly.

2. Make sure that variable "Excel_Location_Path" and "Excel_Location_PathD" in Function Library (see 5th and 6th line of screenshot in Variable declaration in Function Library) correctly points to the data and Keywords 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 and passing it the names of the sheets of Excel files - Keywords and Data. Function func_Read_Excel is importing the Excel data into two QTP / UFT DataTables. Keywords in one DataTable and Data in another. 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.