Designing Keyword Driven Framework mapped at Operation Level – Part 1
In the previous article on Keyword Driven Framework, we covered the basics of the framework such as what Keyword Driven Framework actually is, what are the main components used in this framework, its generic flow and the common Keyword Driven Framework structures that are used most frequently.
We had seen that based upon how keywords are mapped in your framework, you can distinguish the framework in the following 2 ways –
- Case 1: Keywords are mapped to the lowest level operation on an object (this operation usually is a single statement).
- Case 2: Keywords are mapped to a function or action which contains a collection of statements.
In this and the upcoming article, we will cover the first case in detail. We will see how you can create a keyword driven framework where most of the keywords are mapped to the operations at the object level.
Topics that will be covered in this article
- 1) Components that are commonly used in this framework.
- 2) The flow of the test cases in this framework.
Before we begin explaining each of the points mentioned above, let us first revisit the structure of this framework once again so that you get an idea about what framework is being referred to here.
From the above figure you can note that the screenshot shows the code (or flow) for the Login portion of GMail. And each of the keywords (like Set, Click, Sync shown in Column E) are mapped with the actual operations that you perform at the object level (like set value in a text field, clicking on a web button etc). This is the reason we are referring to this framework as the one where keywords are mapped to Operations.
Let us now jump over to the points that we intend to cover in this article.
Components that will be used in this Framework
Before we begin listing down the components that will be used in this framework, the important point you should note here is that in this type of framework you have to ‘first identify keywords and then later you have to map them with your functions’. The implementation of this concept can vary from person to person. So based on how you want to implement this concept, the components of the framework and the test case flow that you define might differ.
In the sample framework that we will create, we will cover the basic steps that would help you learn how to create a keyword driven framework. Let us now see the different components that are normally used with this Keyword Driven Framework. Side by side, we will also mention whether we will be using those components in our present framework or not.
- 1) Excel Sheets to Store Test Case Flow: Normally, the flow of our test scripts (like open login page, enter user id and password, click on login button etc) are written in QTP Actions or Function Libraries. But for this framework, the flow of the test cases will be written in the excel sheets (as shown in the image in the previous section).
And how you store the flows in the excel sheets would depend on you. For example, consider that you have 3 test cases – one for GMail, second one for Facebook and the last one for Yahoo Mail. To store these 3 test cases in the excel sheet, you can either create 1 excel workbook with 3 different sheets. Or you can also create 3 different workbooks each having a single sheet.
One best practice that you can follow here is group the test cases based on their type. For example, suppose you have few test cases for GMail, few for Facebook and few for Yahoo Mail. So, you can create 3 excel workbooks each having multiple sheets. The first workbook will have all the GMail test cases in separate sheets, the second workbook will have all Facebook test cases and so on…
For our framework, we will create a single Excel Workbook which will store the test cases that we create for this framework.
- 2) Function Library: In a Keyword Driven Framework, function library is the most important component. Its also the most complex component to design and script. This is because almost all the important things that your framework does will be scripted in the the function library only. Let us see some of the important things that a function library does in a Keyword Driven Framework.
- a) First and foremost, function library will store the information about what all keywords are available in your framework and how they are mapped to different functions.
- b) Function library contains the code which will read the keywords as and when they are encountered and execute the functions associated with those keywords.
- c) Also, when you write the flow of your test scripts in excel sheets, QTP will not be able to understand it because the flow is not in the syntax which QTP recognizes. So your function library will also contain the code which will read each line from the excel sheet and convert in into the format that QTP understands.
Because of all these reasons mentioned above, Function Library can be considered as the core component in the keyword driven framework.
- 3) QTP Test Script (Driver Script): QTP Test Script (QTP Actions) is one more component that you use commonly in your automation frameworks. But the way the QTP test case (or action) is used in this framework is slightly different from the conventional sense.
Normally, you will use QTP test cases in your framework to write the code (or flow) of the test cases that you want to automate. But in this framework, the test case flow is written in excel sheets. Also most of the important functionality and logic of your framework is written in the function library. Because of this, there is nothing much left that can be done from QTP test script.
So in these situations, QTP test cases are used to just initiate the execution. QTP test cases will contain the code that will just call the function library. After this, the function library will take charge and execute the test cases. Because of this reason, QTP test case is also referred to as Driver Script (because the QTP test case (or action) just drives or initiates the execution).
- 4) Excel Sheets to Store Test Case Data: To make your keyword driven framework more robust and to run the test cases against multiple sets of data, you can store the test data in separate excel sheets. When you store the data separately, you would need to write code in the function library which will fetch the data from the excel sheets. The image below shows how the test case excel sheet will look like if you store the data separately.
In order to keep things simple in our framework, we will not use a separate data sheet and will store the data together with the test case flow only.
- 5) Object Repository: To identify and store the objects in this framework, you can either use Object Repository or use the Descriptive Programming approach in QTP. Based upon which method you use, you would need to write corresponding functions in your code to read and load the objects when the test cases are run. For this example, we will use the Descriptive Programming approach.
Flow of the Test Cases in this Framework
The below image shows the flow in which the test cases will be run in this framework.
1) The execution of the test cases would start from the QTP Test Case (Driver Script).
2) When you run the QTP test case, it will load the function library and will pass the control to it.
3) Based upon the test case that needs to be run, the function library will load the corresponding excel sheet which contains the test case flow.
4) The function library will read each line from the excel sheet, convert it into a format that QTP recognizes and will then execute the line of code.
5) Once all the test cases are executed by the function library, the control will be passed back to the QTP Test Case and the execution will be stopped.
This was all about the introduction to Keyword Driven Framework mapped at Operation Level. In the next article, we will cover, in detail, on how you can create this framework from scratch and write test cases in this framework.
Did you like this article? You can let us know your response using the comments section.