Keyword Driven Framework in QTP

There are various types of frameworks that a user can use in QTP and Keyword Driven Framework is a commonly used framework type among these. The different types of framework that are available in QTP are –

  1. Linear Framework
  2. Modular Framework or Functional Decomposition Framework
  3. Data Driven Framework
  4. Keyword Driven Framework
  5. Hybrid Framework
  6. BPT Framework or Business Process Testing Framework

In this article, we will cover the basics of Keyword Driven Framework.

As the name suggests, Keyword Driven Framework is a framework which involves the use of Keywords. This can be better understood with the help of an example. Consider an example where you have automate a test script that does the following things –

  1. Login to Facebook.
  2. Count the number of messages you received.
  3. Logout from Facebook.

Now if you want to write a script for this test case using pure functional decomposition approach, you will need to create 3 different functions, each of them will take care of login, counting messages, and logout part.

This is what you will do in normal functional decomposition approach. For keyword driven approach, you have to go one step further. You have to find out some keywords for each of these flows and then associate these keywords with the functions that you have created. (A keyword is any text that has some meaningful name).

For example, let us consider that you have created the following 3 functions – fnLogin, fnCountMessages and fnLogout. Now let us identify some keywords for the flows. The keywords can be – Facebook_Login, Count_Messages, Facebook_Logout.

Now what you have to do is associate the keywords with the functions. This can be done in the following way-

  1. Save all the keywords in an excel sheet.
  2. Save all the functions in a function library.
  3. Create a test script associate the function library to this test case.
  4. Now you would have to write some code that will read the keyword from the excel sheet and then call the corresponding function from the function library. The association between the two entities can be achieved through select case statement.
  5. This way you can create a basic keyword driven framework for your test scripts.

Flow of a Keyword Driven Framework

The typical flow of a keyword driven framework is as follows –

1)      When you run the test script in QTP, it will first call the driver function from the function library which has the logic to read keywords from excel sheet.

2)      This driver function reads the keyword from the excel sheet.

3)      The function then identifies the action that is associated with this keyword.

4)      The driver function will then call this function which will do the required operations on the application under test.

5)      Once the function has completed execution, the control moves back to the driver function.

6)      The driver function reads the next keyword and the flow continues till all the keywords are read.

For complete set of articles you can visit QTP Framework page. You can also visit QTP Tutorials page for more tutorials on QTP.

Advertisements
Posted in Uncategorized | Leave a comment

QTP Framework Basics

Let us assume that you are asked to create test scripts for an application. As a test engineer, what would be the basic things you want to accomplish? The most important expectation is that the test script should do the intended work. Other than that wouldn’t you want that your code is easy to understand, can be re-used, needs little maintenance and is scalable? All these are the additional features which if you have, makes your life much much easier. And how do you achieve all these things? Well, this can be done by using a good Automation Framework.

LATEST UPDATES

a) The bottom of this article has links to different QTP Frameworks.

b) All articles on QTP Test Automation Framework contain a download link at the bottom of the article, from where you can download the sample scripts and use it as required.

What is a QTP Framework?

QTP Framework, or in general a Test Automation Framework, is nothing but a set of guidelines which you can follow during scripting to achieve the above mentioned “desired” results. These set of guidelines can be anything such as –

  • – coding standards like the variables names should begin with the type of variable (eg. intNum, strMsg, arrArray), function names should start with fn (eg. fnCalculateSum).
  • – structure of your data sheets, how your workbooks and the individual sheets in them are grouped.
  • – what folder structure is required to be followed to save the test scripts, reusable libraries, object repositories, test run results.
  • – how should test results be stored and displayed.
  • – how different team mates can access that shared repositories, libraries and how they should update these.
  • – and many more…

Following these guidelines would lead to the job being done in a consistent manner which would ultimately result in a framework which will provide you with all the benefits that you had aimed for.

Please note that these are just a set of guidelines and not rules which are compulsory. Even if you don’t follow these guidelines, you would be able to achieve your most important task i.e. running the scripts to see if the application is working fine or not. The only thing is that you might end up spending a lot of effort scripting (if there is no code re-use) and maintenance would turn out to be a tough nut to crack.

Salient Features of a Test Automation Framework

Following are the features that should be available in a good automation framework.

  • a) The framework should be created in such a way that it helps achieve maximum possible re-use.
  • b) The test scripts should be easy to understand and maintain.
  • c) The framework should be designed in such a way that all different components such as test cases, function libraries, object repositories, data sheets, configuration files and test results are stored in separate folders. This would help the users understand the framework quickly.
  • d) Data parameterization should be done to keep the code separate from data, so that the same code can be re-used for different sets of data.
  • e) Run Results should make sense and should be easy to understand. You can also provide high level and detailed test results separately.
  • f) Proper error handling techniques should be used. You can also providing screenshots of the failed test cases.
  • g) When test cases are run in batch mode, failure of 1 test case shouldn’t affect the execution of the remaining test scripts in the batch.
  • h) You can also write QTP AOM code in VBScript which can act as the starting point for the execution of test cases.
  • i) The framework may also include email (and if required SMS) functionality so that the test results are automatically mailed/sms’ed to the stakeholders.

Other than these features, you can also include various other features based on your requirements.

Frameworks used in QTP

Following are the different types of QTP Frameworks that you can use while creating test scripts. (Click on the links below for detailed articles on each of these QTP frameworks)

1) Linear Framework in QTP – This is the most basic framework where you write your script as is. That is, with this approach you write all the steps one after the other in a step by step manner.
2) Modular Framework in QTP – In this framework, you write the entire code into different functions and then you call these functions as and when required. These functions can be both reusable and non-reusable.
3) QTP Data Driven Framework – Here, your data is kept separate from the code, preferable in excel workbooks. This helps you execute the same code for multiple sets of data.
4) Keyword Driven Framework in QTP – In this type of QTP Framework, you can create different keywords and associate different actions with these keywords. When QTP encounters a particular framework, it will execute the action associated with that framework.
5) QTP Hybrid Framework – Hybrid framework is a combination of one or more frameworks discussed above. Based upon your requirements, you can combine the features of any of the above frameworks. The resultant framework would be a Hybrid framework.
6) BPT Framework in QTP – In this QTP Framework, you can divide your test case flow into multiple Business Components. You can then re-use these components as many times as required. You need Quality Center access in order to use BPT Framework. Also you need to acquire BPT license from HP in order to use this framework.

For more QTP tutorials, please visit QTP Tutorials page in AutomationRepository.com

Posted in QTP Frameworks | Leave a comment