Pages

Sunday, March 13

How to design Automation Frameworks in QTP


Hello Friends!

In this post, we are going to discuss about Automation Framework! I'm not going to write any bookish definitions here. It's all what I learned from practical experience.

Okey!

First thing first...


What is framework?


Do you watch movies in Cinema Hall? I know you do!!

Take a moment and think about what happens starting from the point you enter in Cinema Hall to the point you come out. Here are few typical steps..

- You enter in hall >> go the ticket window >> pick a movie broacher somewhere nearby ticket window

- Choose a particular movie you wanna watch (decision influenced by the choice of wife/girlfriend!!)

- Come in the queue and wait for your turn, pay by card and get the ticket.

- On ticket you find some very important information i.e. show start time, Audi No. (Hall No.) etc.

- You go into the given sign-posted Audi, 5-10 minutes earlier then show time, watch the movie (along with other activities ;) ...... and so on....

Everything is planned.. In order!!  Isn’t it? This is nothing but a framework..


Automation Framework is a set of guidelines and process you use to manage and optimize your automation testing. 

In simple words, Framework is a way to do the things in fashioned and organized manner! Framework is nothing but a concept.


 
Why I need a Framework?:

Now assume that Cinema Hall doesn’t follow any framework.


- You enter in Cinema Hall, go the ticket window, - but there is no movie broacher nearby ticket window??

- You go to the ticket window, but they don’t accept credit/debit cards?? (and you don't carry cash..)
- Okay! You somehow managed to buy ticket, but ticket doesn’t tell you show time and Audi/Hall No.??

- You reached into the Audi but movie has not been started on time??

Would you like to go again in this Cinema Hall?? I'm sure not..

It's always possible to work without framework but you'll be doing a lot of rework, everything will be here & there and in most of the time you will end-up with a mess, especially in the large projects.



Framework lets you predefine your automation plans, strategies and how you are going to proceed.



Types of Framework:

Framework can be of several types, but here are three main types of frameworks-

1. Keyword driven framework
2. Data driven framework
3. Hybrid framework

But this is only theoretical. Practically, there is no 'Chinese Wall' between the framework types.

In every organization you work, you'll find that it's quite different from the other and not only on organization level, you can feel the difference within different projects!

Yess, but most of the them could be mapped with Hybrid type and I like it!! :)
Hybrid framework has no boundaries and open to take benefit of all possible type of frameworks.



How to design a framework?

I have done a lot of automation projects and designed a lot a frameworks, but seriously guys, I never used any particular type of framework!

Practically, every application/project has its own expectation. You just need to start your work in organized way and believe me friends, at the end of the day; your framework will be ready automatically!! Sounds crazy??

You can't design a complete framework and then start automation! You start automation and framework will start building simultaneously. 

The first step of any test automation framework is to do a quick POC with few high priority test cases aka 'smoke tests'. By doing POC, you will identify the object identification issues, challenges, complexities, required test-data and limitation you have. Once you are ready with this information, you can proceed with next steps. On the basis of above information, you can decide what type of framework is most suitable to you.


But before starting, you must take some time to decide your strategies about..

1. Object Identification
2. Test-Data
3. Function Library
4. Error Handling
5. Controller/Driver script
6. Documents and Manuals
7. Test Reults

1. Object Identification:
One of the most important aspect of QTP automation is - How to identify objects i.e. using Object Repository(OR) or Descriptive programming(DP) or both. As per my understanding, dont't try to stick on one particular. Depending on the application/object types, mixed approach is most fruitful most of the time.

Although  both OR and DP have their own pros n cons, but remember, you get full benefit of QTP only when you use OR like debugging, chechpoints etc. So make sure how to identify objects.

Many claim that DP should be used for whole project without using any OR approach, but I disagree. DP is nice thing to use but should be used only when required like if your application is having dynamic objects etc. Doing whole automation using DP without any solid reason is not sensible (personal opinion!).

2. Test-Data:
How to manage you data? DataTable or Excel or may be flat/csv files.

3. Function Library:
Function library could be QTP specific (.qfl) or external (i.e. .vbs). Be clear about what type of function libraries you are going to use and why.

4. Error Handling:
What's your plan for handling errors? Be clear about it. Are you going to use QTP's Recovery Scenarios or you will be writing your own .vbs functions?

5. Controller script:
Design a controller script, which will control all your automation. It should be neat. This helps to understand what actually you are going to call.

6. Documents and Manuals:
Keep all the documentation, user guide/manuals, keywords descriptions here.
 
7. Test Results:
Result is probably most important part of the framework. Put extra attention to results.. always!!

Why? Because result is the face of your framework! This is what you show to world. If your result is fantastic, nobody bothers what type of framework you use, what the hell you have written in your functions!! :) But if results are not flashy.. then.. you know!!

So never underestimate the importance of the results. It must be very well presented.


Create different folder for the these seven things and keep data in folders accordingly.

This was the one part.

Apart from this, from first day of your automation, keep only one thing in your mind.. follow general good practices!

Here are few points need to be take care in designing successful framework.

  • Try to document each and every thing, as much as you can! like comments in script, modification etc.
  • Don't stick with any particular object identification, use mix of OR and DP
  • While using OR, don't use record and playback, just add object in the object repository and code the script manually.
  • Follow proper Naming-Conventions for all your variables, functions, files.
  • Define all the variables in you scripts, use Option Explicit.
  • Try to keep you functions small to enhance reusability and portability.
  • Never hard code any data in the scripts, use parametrization.
  • Take regular back-up of your work.

Okey guys! Please share your views by posting comments.


Related Posts:

QTP - General Tips