Till now we have covered QTP Linear Framework, Modular Framework and Data Driven Framework as part of the QTP Framework series of articles. Beginning with this article, we will cover the various aspects of QTP Keyword Driven Framework in detail. We will be covering all these details together with examples and downloadable code in 4 to 5 articles.
What will you read in this article
In this article, you will read the following topis that will help you understand the basic concepts of Keyword Driven Framework.
- 1) What is Keyword Driven Framework?
- 2) The main components that are part of almost all the Keyword Driven Frameworks.
- 3) Generic flow of a Keyword Driven Framework.
- 4) Some commonly used Keyword Driven Framework structures – Screenshots.
What is Keyword Driven Framework?
Keyword Driven Framework is a type of QTP Framework where for a particular test case, you would first identify a set of Keywords and then associate an action (or function) which each of these keywords.
Let us understand this concept with the help of an example. Let us consider that you have to automate a flow where you would need to do the following things in GMail.
- 1) Login to GMail.
- 2) Count the number of unread emails in Inbox.
- 3) Logout from GMail.
Now, let’s see how we can approach this test case from Keyword Driven Framework perspective. If you look at the above test case from pure Modular Framework point of view, you will be able to easily identify that you would need to write 3 different functions for the above test case. These 3 functions will be used to – Login to Gmail, count unread emails and logout.
Once you have identified the functions, the next step is to identify some keywords and then associate the functions with these keywords. Below figure shows a pictorial representation of this concept.
From the above image you can see that basically a Keyword Driven Framework is nothing but a collection of keywords & functions (or actions or operations) and the association between these two entities. So to create a keyword driven framework, all you have to do is –
- a) identify keywords and store them somewhere,
- b) create functions for the business flows, and
- c) associate these functions with the keywords.
Common Components and Workflow of a Keyword Driven Framework
The major difference between the Keyword Driven Framework and others is the use of “Keywords”. Most of the other things remain the same. You need to identify the keyword and store them somewhere.
Below is the list of common components that you will find in most of the keyword driven frameworks.
1) Excel Sheet to Store the Keywords: This is the only extra component that you will find in a Keyword Driven Framework. Once you have identified the required keywords, you can store them in an excel sheet. You would need to write some code that will first open this excel sheet and copy the keywords. Based on the keyword, QTP will call the function associated with it.
2) Function Library: In Keyword Driven Framework, function libraries usually play a very important role. You would have to built all the necessary intelligence in the function library so that it can read the excel sheets and call the different functions based on the Keywords.
3) Data Sheets: As with the other frameworks, you can use the data sheets to store the test data that will be used in the application.
4) Object Repository: Based on the design of your Keyword Driven Framework, you can either use an object repository or completely skip it (if you are using Descriptive Programming approach).
5) Test Scripts: Again based on the design of your framework, you can have separate test scripts for each manual test case or a single driver script that will execute all the test cases. (This will be covered in detail in the upcoming articles).
The below image shows the generic workflow of Keyword Driven Framework.
From the above figure, you can see that the generic flow of a Keyword Driven Framework is something like this –
1) Test Script or Driven Script calls the main function library. This function library contains the code that reads the keywords from the excel sheet.
2) The function library opens the excel sheet and reads the first keyword associated with the test case.
3) The function library calls the function associated with this keyword.
4) The function then performs all the required actions on the application that is being tested.
5) Control returns back to main function (in Step 2) which then reads the next keyword. Steps 2 to 5 are repeated till all the keywords associated with a particular test case are called.
Some commonly used Keyword Driven Framework Structures
As mentioned in the beginning of the article, the basic premise of a Keyword Driven Framework is that – you identify some keywords and write associated functions. This generic statement provides you with a lot of scope to improvise and put in your own thoughts to build this framework.
That’s the reason why, if you search for Keyword Driven Frameworks on the internet, you would find a variety of ways in which people have implemented this idea.
Based on the usage of Keywords, you can broadly classify the framework in 2 different types –
1) Frameworks where Keywords are associated with entire functions. Here, the functions are a collection of different operations or steps. (like Login function, which is a collection of multiple steps). So when you associate a keyword with the function, it means that a single keyword is associated with a collection of steps.
2) Frameworks where Keywords are associated with the lowest level operation on an object. Here, the lowest level operation is the operation that you perform on an object. Like click operation on button, set or type operation on a text box. So the keywords that you will use in this case would be Set, Click, Type etc which will be associated with functions which will just click on the object or enter value in a text box. In other words, the function associated with this keyword will do only 1 thing.
Let us understand the above two points with the help of examples. We will use the following 3 test cases as an example –
- 1) TC_01: Login to GMail, find how many emails you received today and then logout.
- 2) TC_02: Login to GMail, send an email to one of your contacts and then logout.
- 3) TC_03: Login to Facebook, find how many notifications you have and then logout.
Frameworks where Keywords are associated with entire functions
Example 1: This is one of the most common formats of Keyword Driven Frameworks that you will see around (with slight variations here and there). Here, you need to specify all the keywords against a test case. For ease of understanding, you would also need to provide a description for each of the keywords. The below image shows how the keyword excel sheet would look like.
Example 2: This is another common structure that is used very frequently and is quite similar to the previous one. The only difference is that the keyword names are self explanatory and hence you don’t need to provide the description for each keyword. The keywords can be arranged horizontally or vertically as per your wish. The below image shows the structure of the keyword excel sheet with horizontally aligned keywords.
Frameworks where Keywords are associated with the lowest level operation on an object
Example: As mentioned previously also, in this type of Keyword Driven Framework design, the keyword is associated with a small operation (like click button, set value in some text box) rather than associating it with an entire function (like login, logout etc). Also this is a framework design that is quite complex and used rarely. Image below shows the screenshot of Login component of GMail.
In the above example, Set, Click and Sync are the keywords that will be associated with corresponding set, click and sync functions provided by QTP. All other functions will also be written in the same way in this framework design.
This was all about the basics of Keyword Driven Framework. We would be covering each of the above mentioned examples in detail (together with downloadable code) in upcoming articles.
Would you like to share any other Keyword Driven Framework format that that we might have missed here? Let us know your views about this article using the comments section.