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

=> Click Here For The QTP Training Tutorials Series

What is Test Automation Framework and what is QTP Framework?

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

Test Automation Frameworks

Test Automation Frameworks

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 failure or stopping of others).

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

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

There are various names and types of frameworks.  Given below is the list of frameworks according to me.

Types of Automation Frameworks (Applies for QTP Framework)

types of automation frameworks

  • Linear: The simplest form of creating a test. Just write one single program without modularity in sequential steps
  • Keyword-driven: Create different keywords for a different set of operations and in the main script we can just refer to these keywords.
  • Data-driven: To run the same set of operations on multiple sets of data that are kept in separate files, mostly excel sheets.
  • Hybrid: A combination framework that can be partly data-driven and partly keyword-driven.
  • 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 keeping it going.

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

  • Open gmail.com
  • Click on “Create Account”
  • Enter the details
  • Verify the details
  • Create an 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

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

Advantages:

  • Simplicity: For beginner programmers, this method is apt.
  • Time: It does not take a lot of time to create the test.
  • Very little planning is required

Disadvantages:

  • No reusability at all.
  • 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 the gmail.com page too. Hence, lots of repetition.
  • All the data is directly embedded into the code. Hardcoding does not allow the code to be used for any other set of data.
  • Error-prone and maintenance is difficult

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

The components of test assets in this kind of framework 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 these 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?

  • Launching of Gmail and arriving at the ‘Google Accounts’ page. This is given as 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.
  • Enter the details and validate them – You can further break this up into positive and negative blocks to include more levels of modularity.
  • Account creation – Final level of validation and accomplishing the task at hand.

Once you have arrived here, you have not only identified components that can be called over and over again, but you have also broken your 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 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 with a resource for your QTP test.  Typically a function library can be a file of 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

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 with 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 the name for this framework.

The components of test assets in this kind of framework 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 is exactly the next step. Data driving your tests and the approach where we do this is a data-driven framework.

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

=> Visit Here For The QTP Training Tutorials Series

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

Related Post

Leave a Reply

Your email address will not be published.