QTP Frameworks – Test Automation Frameworks – Keyword Driven and Linear Framework Examples – QTP Tutorial #17

What is Test Automation Framework and what is QTP Framework?

In the context of successful implementation of QTP for a software testing project we often come across the concept of frameworks. Framework is nothing but the approach that we consistently follow during the automation process – a set of guidelines.

Personally, I don’t like to give names and say that one works better than the other. The selection of a certain framework is not the beginning of a project. It is the reverse that is true. In the process of devising a testing strategy you build the rules that are applicable to the tester’s current situation and that right there is your framework.

Having said that, the following are some of the important points we need to consider:

  1. Reusability
  2. Script’s easy maintenance
  3. Readability of scripts
  4. Good workable folder structure for all the test assets
  5. No hard coding values
  6. No cascade of failures. (i.e. if one test fails, it should not cause the failure or stopping of the others)

This is the basic list and more can be added based on the requirement.

Any testing strategy that tries to incorporate some or all of these above points is your Test Automation Framework.

There are various names and types of frameworks. The following is the list of frameworks according to me:

Types of Automation Frameworks: (applies for QTP Framework)

types of automation frameworks

  1. Linear – Simplest form of creating a test. Just write a one single program without modularity in sequential steps
  2. Keyword driven – Create different keywords for different set of operations and in the main script we can just refer to these keywords.
  3. Data driven – To run same set of operations on multiple sets of data that are kept in separate files, mostly excel sheets.
  4. Hybrid – A combination framework that can be partly data driven and partly keyword driven
  5. BPT – This just means that programs are broken down into business components and are used with one or the other of the above types of frameworks

Linear Framework

As discussed this approach involves simply writing the code as we record and keep going.

For example, if the operation that you have to verify is the creation of a new account in gmail the following will be the steps:

a) Open gmail.com
b) Click on ‘Create Account’
c) Enter the details
d) Verify the details
e) Create the account

 'Open GMail
 SystemUtil.Run "iexplore.exe", "http://www.gmail.com"
 'Page Sync
 Browser("Gmail").Page("Gmail").Sync
 ‘Click on create account
 Browser("Gmail").Page("Gmail").WebLink(“Create Account”).Click
 ‘Enter the details
 Browser("Gmail").Page("Google Accounts").WebEdit(“First Name”).Set “Swati”
 Browser("Gmail").Page("Google Accounts").WebEdit(“Last Name”).Set “test”
 ‘Fill in several other details
 ‘Submit
 Browser("Gmail").Page("Google Accounts").WebButton(“Next Step”).click

The above is an example of how a program that uses the linear method looks like. It is obvious at this point what the advantages and disadvantages of this method are.

Advantages:

  1. Simplicity. For beginner programmer this method is apt
  2. Time – It does not take a lot of time to create the test
  3. Very little planning is required

Disadvantages:

  1. No reusability at all
  2. If there is another script that verifies a certain aspect of the ‘Google Accounts’ Page then you will have to rewrite the code to launch gmail.com page too. So lots of repetition.
  3. All the data is directly embedded into code. The hard coding does not let the code be used for any other set of data.
  4. Error prone and maintenance is difficult

While the cons outweigh the pros, this method can be used when your aim is strictly to accomplish a task without validations.

The components or test assets in this kind of frameworks are:

  1. Test script
  2. Object repository (This can be avoided by using descriptive programming if needed)

Keyword driven Framework

How can we make the above linear framework test better? How can we overcome the cons?

Obviously, we need reusability, modularity and readability. Trying to incorporate these features and arriving at an optimum solution is nothing but an attempt at creating a new, more improved framework.

What are the reusable components?

------------

  1. Launching of gmail and arriving at the ‘Google Accounts’ page. This is a given, since validating this page means to first get here. ‘GoTo Google Account” – can be made into a separate function that can be called over and over again.
  2. Enter the details and validating them – You can further break this up into positive and negative blocks to include more level of modularity
  3. Account creation – The final level of validation and accomplishing the task at hand

Once you have arrived here, not only have you identified components that can be called over and over again, but you have also broken you linear program into modules.

Functions:

So far in our series we have not dealt with functions. Functions are nothing but a piece of code that does a certain operations. It accepts input parameters from the program that calls it and returns value to it.

As a general practice all the reusable pieces of code are grouped into a file that contains all the reusable functions. This file is associated as a resource to your QTP test.  Typically a function library can be a file of the type: .vbs, .txt or .qfl

Back to our example – This is how the function library file can be:

 Function gotoGoogleAccount()
 'Open Gmail
 SystemUtil.Run "iexplore.exe", "http://www.gmail.com"
 'Page Sync
 Browser("Gmail").Page("Gmail").Sync
 ‘Click on create account
 Browser("Gmail").Page("Gmail").WebLink(“Create Account”).Click
 ‘Enter the details
 End Function
 Function EnterDetails()
 Browser("Gmail").Page("Google Accounts").WebEdit(“First Name”).Set “Swati”
 Browser("Gmail").Page("Google Accounts").WebEdit(“Last Name”).Set “test”
 ‘Fill in several other details
 End Function

 Function SubmitToCreate()
 ‘Submit
 Browser("Gmail").Page("Google Accounts").WebButton(“Next Step”).click
 End Function

Now your actual script will be:

 'Open GMail
 gotoGoogleAccount()
 ‘Enter the details
 EnterDetails()
 ‘Submit
 SubmitToCreate()

From the above program it is now clear that we have achieved readability, modularity and if in case another program wants to use the login function, we can surely reuse it. All you have to do is associate the function library to that new test too and you are good to go.

You can also see that in your script the function names are functioning as if they are VBScript’s keywords and hence the name for this framework.

The components or test assets in this kind of frameworks are:

  1. Test scripts
  2. Shared OR
  3. Shared function library

Now, what else would make this program even better? If we could make the EnterDetails() function to take different sets of data and create different accounts and not be limited to the data that we hard coded into the program. That exactly is the next step. Data driving your tests and the approach where we do this is the data driven framework.

We will discuss Data driven and Hybrid frameworks in detail in the coming tutorial.

If you have any QTP framework related issues that you are facing that is not covered in these articles, do let us know. We will most definitely try to answer your questions.



The Best Software Testing Training You'll Ever Get!

software testing QA training

16 comments ↓

#1 Sheetal Borate on 05.09.13 at 7:55 am

Thanks for explaining this in simple words. I have doubt about folder structure which is very important part of any automation framework. what is it’s importance and is there any rule to define it in qtp framework.

#2 Swati on 05.11.13 at 8:26 pm

@Sheetal: First of all, excellent question. The folder structure is not a standard. Usually it is in a way that the path is similar in both your local machine and the QC (if you are using it). So, in short if QC and QTP integration is used,make sure the folders in both of them match.

#3 saravanan on 05.15.13 at 3:39 am

Hi, because i am a beginner in QTP, can you please tell me some more practical examples and scenarios for where this keyword driven framework can be effectively used.

Thanks in advance

#4 Hitesh on 05.21.13 at 1:54 pm

Nice Article on Framework.
I have a question, should we directly Run QTP on Live site testing?

#5 Swati on 05.26.13 at 10:03 pm

@Hitesh: Sorry,I am not sure I understand your question. The way QTP works is: You have it installed on a machine. You run your AUT, web or windows based. Record the operations you perform on AUT, modify them and create your test.

Is that what you meant? if not, please provide more information and I will try to answer your question.

#6 subha on 05.31.13 at 11:15 am

hi,i understand the concept ,could you give me another example with excel sheet.

#7 Swati on 06.01.13 at 4:12 pm

@Subha: Using excel sheets for data-driven tests is discussed in article 18. Please check that and let me know if you need any further explanation.

#8 vijay on 10.08.13 at 4:10 pm

all tutorials , exampls super.. realy easy to learn…
Thank you…
i have few inconvinient in below queries…..

How to add repository for web application?
is it possible?
how to identify web page name and object names?
pls help me…

#9 satheesh on 10.23.13 at 2:19 pm

how to working Qtp in desktop application with screen short ple any one help me …

#10 satheesh on 10.23.13 at 2:21 pm

how to working Qtp on desk top Application with screen short Or Example ple help me…

#11 namrata on 11.20.13 at 1:57 pm

First of all nice article.I want to ask how to associate file as resource to QTP test ?

#12 Swaroop on 12.16.13 at 12:38 pm

@Swati – Nice explanation madm

@Namrata, Once you write ur function in the function library, just save it & go to file menu there u have an option called “Associate function library(ur function library name) with Script (ur script name) “

#13 vaidehi on 03.05.14 at 5:25 am

Very nice article!!!

#14 manish dave on 03.20.14 at 10:01 am

nice article .
in keyword driven framework , can you pls explain the use of keywords.

#15 srinivas on 05.05.14 at 6:01 am

Thanks for the nice tutorial.

The problem i am having is that i have a function ready and when i’m trying to call it, i get the type mismatch error. How can i resolve this in UFT 12.0?

#16 raviteja on 10.31.14 at 6:44 am

Hi this teja…i have some questions .can u please explain to me.
1.how how can you take a data from test data to driver script?
2.can u please tell me about frame work folder structure for data driven,keyword driven,hybrid driven frameworks?

Leave a Comment