Tuesday, September 24, 2013

Keyword Driven Framework

Keyword Driven Framework with an Example

Keyword Driven Frameworks can be created using low level (operational level) keywords or using higher level (functional level) keywords. In this post we will look into later one.

In order to create a framework like this:

1. Create a new Object Repository and add objects to it. Objects related to Flights application (Login window, Flight Reservation window and Flights Table window).
2. Record a test where you open the Flights application, login into the application, create a new order and at last logout of the application.
3. Divide the above recordings into separate functions as you can see the functions of Library1 below.
4. Write a function (see function 1 of Library2) that reads an Excel and accordingly calls the functions of Library 1.

Below is the folder structure:



Let’s try to run the framework:

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

1. Make sure that variable "sExcelLocation" in Function Library2 correctly points to the data (read Keywords.xls in the folder structure above) file.
2. When you open the test (UFT_Test_Cases), you must associate both the Function Libraries (Library1 and Library2) with the test.
        File (Menu) -> Settings.
In the Test Settings dialog that opens, go to Resources and associate the Function Library.
3. You must associate Object Repository with the test.
        Resources (Menu) -> Associate Repositories
Now try to Run this framework.

What this framework does:

This framework inserts a new order in the Flights application.

There are four parts to this framework (UFT_Test_Cases, Function Libraries, Excel and an Object Repository):

1. UFT Test (UFT_Test_Cases)


2. Function Library (Function_Library)

Function 1 in Function Library 1


Function 2 in Function Library 1


Function 3 in Function Library 1


Function 4 in Function Library 1


Function 5 in Function Library 1


Function 1 in Function Library 2


3. An Excel Sheet (Keywords)


4. An Object Repository file.

Explanation of the above framework:

In this keyword driven framework, Keywords are associated with functions. Keywords can also be associated with operations on objects like click etc. In UFT Test (above) we are using built-in Environment variable “TestName”, in order to get the name of the current test and pass this to func_Read_Keywords (Function 1 of Function Library2). In short UFT Test is calling func_Read_Keywords, which in turn verifies if the ‘TestCaseNo.’ in Excel [first column] matches the UFT_Test_Case name. If it matches, Perform_Flow function (Function 1 in Function Library1) is called. Perform_Flow function runs the entire test case by calling each of the required functions (open application, create order etc.) separately.

Some facts about Keyword Driven Frameworks:

Keywords can be reused across multiple test cases. Trivial changes are bearable. The maintenance is quite low, relatively.

Keyword driven framework is considered as more complicated than Data Driven framework, but once created it is easiest to maintain as said earlier. As compared to Data Driven testing, keyword driven test cases are longer.