Designing Keyword Driven Framework mapped at Functional Level – Part 1
In the previous two articles we saw how to create a Keyword Driven Framework where the keywords are mapped at Operation Level. In this article, we will cover a different type of Keyword Driven Framework – the one where the keywords are mapped at Functional Level.
Keyword Driven Framework mapped at Functional Level is the most commonly used Keyword Driven Framework type. How its actually implemented may vary from project to project. But the basic premise always remains the same – “define keywords and assign them to actions or functions”.
The important point that should be noted in this framework is that the keywords are mapped to a function which will contain more than one line of code. For example, you can have a keyword called ‘Login’ that in turn can be mapped to function called fnLogin. Now, this function will contain the few lines of code that will open the application, enter user name and password and then click on Submit button.
This is different from the Keyword Driven Framework implementation mapped at Operational Level, where the keyword is mapped to an action performed at object level. (For more details about the basics of the Keyword Driven Framework, refer – Basics of Keyword Driven Framework)
Topics that will be covered in this article
1) The components that are commonly used with this framework.
2) Flow of the test cases in this framework.
Let us see each of these points one by one.
Common Components used in Keyword Driven Framework mapped at Functional Level
Following are the components that are commonly used with this framework –
1) Test Scripts or Driver Script: As mentioned in the beginning of this article, in this type of framework all the keywords are associated with some functions. So naturally, the entire test case flow would be composed of multiple functions.
For example, consider a test case where the you have to login to Gmail, send an email and then you have to Logout from Gmail. Looking at the test case, you can easily figure out that the test case can be divided into 3 functions –
Normally what we do is – create the functions and then save them in the function library.Then we will create a test script where we will call all these functions one after the other. This is what you do in functional decomposition framework also.
But in the keyword driven framework, the keywords, and hence the flow of the test case are actually specified in the excel sheets (refer below image for example). Now, since the flow of the test case is mentioned in excel sheets, the actual test script will not store the test case flow. Hence the test script will not be used the way we do it in other framework types.
So in this case, the test script would be used as a driver script whose sole purpose would be to pass the control on to the function library.
2) Object Repository: As is the case with all the QTP Framework Types, you can use the Object Repository to store the properties of the objects and then call the same in the test scripts. You can also use the Descriptive Programming approach if you wish to skip using the Object Repository. As part of this framework creation, we will be using the Object Repository to store the object properties.
3) Function Library: In the Keyword Driven Framework, the operations of the function library can be broadly classified into the following two types –
- a) Application Related Flow: This is the most common purpose for which the function library is used for in all the framework types. Application flow means that the function library will contain functions that will depict the flow of the test cases. For example, the function library may contain functions such as Login and Logout which are actually a part of the application under test.
- b) Framework Related Flow: This part of the function library deals with the functions that are not directly related to the application as such. These are the functions which are related to the framework. For example, functions such as read keyword from excel. These types of functions are application independent and can be used at all the places where this framework is implemented.
NOTE: If you are going to implement your Keyword Driven Framework for different applications, you may want to create two separate function libraries for application related flow and framework related flow. This will help you implement the framework for different applications in a smooth manner.
4) Excel Sheets to Store Data: You can use excel sheets to store the data and then use it in your test scripts. You can choose any format for the data sheets as per your requirement. In order to keep things simple, we will be hard-coding the data in the test scripts. Hence we will not be using any data sheets for this framework implementation.
5) Excel Sheets to Store Keywords: In this framework, all the keywords (and hence the flow) associated to the test cases will be stored in excel sheets. The way in which the keywords are added in the excel sheets may differ from project to project. Also, together with the keywords, you can add additional details in the excel sheets which would make the flow more readable. For example, you can –
- a) Add description along with the Keywords: This would make the test case flow more readable.
- b) Add a Result column together with the Keywords: You can add a Result column next to the Keywords and then you can write a function which would update each keyword as pass or fail when the test script is run. So if a test run fails, you can easily figure out till which point the test case has run and at which place it has failed.
- c) Add an execute Column along with the Keywords: If you have Keywords independent of each other, you can add an Execute column along with the Keywords. You can have values as Yes and No in the execute column. You can then write a function which will first check the Execute column and then will execute only those keywords where the value is set as Yes.
The below figure depicts how the excel sheet would look like.
As part of this framework, we will be adding only the keywords and the description about them. But you can try the remaining concepts on your own and see how it goes.
Flow of the Test Scripts in this Framework
In this type of Keyword Driven Framework, the flow of the test scripts will be as follows –
1) The execution of the test cases would start from the QTP Test Script. In this framework, we will create a separate test script for each test case that needs to be automated.
2) The test script will give a call to the function library which contains the code to read the excel sheets containing the keywords. (There will be 2 separate function libraries in the framework. One which handles the framework flow and the other which handles the application flow)
3) The function will read the excel sheet and depending upon the keyword encountered, it will give a call to the function from the ‘application related’ function library.
4) This function would perform the required actions on the application and once done, it would return the control back to the calling function.
The below image depicts the above mentioned flow.
This was the basic information of Keyword Driven Framework mapped at Functional Level. In the next article, we will cover, in detail, on how to create this framework from scratch and write test cases in this framework.
What are your thoughts about this article? You can let us know your response using the comments section.