Thursday 25 December 2014

FRAMEWORK STRUCTURE

Table of Contents  INTRODUCTION        PURPOSE     FRAMEWORK STRUCTURE     Function Library     Object Repository      Database    Application Scenario Files    Sequence File   Initialization VB Script     Driver Script       Test Case List File  
TIPS ON DEVELOPING A STRONG & ROBUST AUTOMATION FRAMEWORK        Introduction
The way software industry moved from manual testing to test automation, it is now moving towards Business Process Automation. Business Process Automation works towards making automation frameworks more and more meaningful to the Functional Subject Matter Experts by involving them in Test Automation as much as possible thereby making Test Automation business driven. To keep pace with the latest trends in the industry and to have an edge over its competitors, it is important for a testing organization to adapt itself to this new approach. One tool which is in line with this approach is Mercury’s Business Process Testing. Being Industry’s first web based test design solution; BPT is one step further to the Keyword Driven Test Automation approach.
For any Software Testing Organization, moving to a new tool like BPT is a big step. For it to justify this big step, it is important for the organization to have successfully implemented the Keyword Driven Test Automation Approach. This is because, it is easy for a project to implement BPT if it is already following keyword driven approach than for a project which is not. One of the benefits of using this approach is the automation effort saved due to reusability of the keyword components across different applications. This benefit is realized when the extent of reusability is high. This is possible when the type (eg. Web, VB, SAP, Delphi etc) is common across applications to be automated, because keyword components built with a particular QTP/WinRunner Add-in can be reused only with applications that can work with that Add-in.
Today, most organizations are developing web based application as against client server or mainframe applications. In some instances, organizations are converting their applications from legacy systems to web. Considering all this, it makes business sense for Testing Organizations to go for Keyword Driven Test Automation Framework for Web-based applications.
2.    Purpose
This document is an attempt to build a Keyword Driven Test Automation Framework which can be used across different web based applications. In this approach, the endeavor is to build a lot of application independent reusable keyword components so that they can directly used for another web application without spending any extra effort. With this framework in place, whenever we need to automate a web based application, we would not need to start from scratch, but use the application independent keyword components to the extent possible and create application specific components for the specific needs.
3.    Framework Structure
The framework consists of the following components.
•    Function Library
•    Object Repository
•    Database
•    Application Scenario Files
•    Initialization VB Script
•    Sequence File
•    Driver Script
•    Test Case List File
The directory structure in which these components are arranged is as shown below.
3.1.    Function Library
In this approach, all the coding logic is in the form of user defined VB script functions. All of these functions are stored in function libraries (vbs file). There is absolutely no scripting done outside of the function library except for the Driver Script (explained in section 3.7). For each application, there are two function libraries, one which contains all the application independent functions (or common functions) and another that has application specific functions. While developing scripts for an application, the endeavor would be make use of the application independent functions as much as possible. In case, some functionalities require application specific functions, create them and put them in the application specific function library.
The common function library has a function (ExecuteScenarioFile) which reads the keywords, objects and other parameters from the Scenario File (described later in this document) and makes calls to appropriate functions in the function library. This is the only function which is called from outside of the function library (this function is called from the Driver Script).
Some of the common functions that can be created for web applications are as given below,
1.    Close all browser windows and launch a new instance of browser.
2.    Click on a Web Button with all error handling.
3.    Enter data in a Web Edit object with all error handling.
4.    Import data from MS Access to run time data table.
5.    Verify text on a Web page with all error handling.
All the function library files (.vbs files) are kept in the Function Library folder in the directory structure.
3.2.    Object Repository
Each application automated has a different object repository file and there is only one object repository for each application. All the object repository files (.tsr files) are kept in the Object Repository folder in the directory structure.
3.3.    Database
All the test data is stored in MS Access database. The database structure is designed in such a way that there is more or less one table for each screen on the application. Almost every table has Test Case Id as one of the columns and is either the only primary key or one of the primary key columns. The Test Case Id represents a record or the data used for iteration. The database might have 100 sets of data, but the user might want to execute only 10 of them. The Test Case Id helps in this situation by providing the user with the option to select only certain sets of data.
The connection to this database is established from QTP by creating a System DSN for the database and using this DSN in the script. Ideally, we might want to have one database file created for each application. But, we can also have one database for multiple applications to save disk space.
All the database files (.mdb files) are kept in the Database folder in the directory structure.
3.4.    Application Scenario Files
An application scenario file is a spreadsheet which contains keywords, objects and other parameters arranged in the desired order to form a test scenario. It is from this file that QTP reads information and performs actions on the application. This spreadsheet also serves as test scenario documentation, thanks to the easy to understand and English like keywords. Therefore, we do not need to have separate effort spent for test case documentation thereby saving time, effort and cost. It is this feature that makes the keyword driven framework so powerful.
The snapshot below shows how an application scenario file looks.
The application scenario file makes it very easy for the functional SME to create an automated test by selecting keywords from the dropdown without any programming knowledge.
The brains behind the keywords are the user defined functions which are called to make it work for the SME. Let us understand this with an example,
The keyword “Enter data” is used to enter data into any field (WebEdit, WebList or WebCheckBox) on any web page by passing appropriate objects and parameters to the keyword. This is possible because of a function created to read the keyword, objects and parameters from the application scenario file and make calls to appropriate WebEdit, WebList and Web Check Box functions. So, we can make a keyword reusable by making its building blocks (user defined functions) reusable.
Therefore, the key to saving automation effort while following this approach is to create as many common web functions as possible, so that they can be reused to the maximum extent.
Each application has an application folder and all the application scenario files (.xls files) belonging to that application are kept in the corresponding application folder.
3.5.    Sequence File
Sequence File is a like configuration file which contains information required to do the initialization settings to the Driver QTP Script for a particular application. The Sequence File is in the form of a spreadsheet which has an entry for each application and settings data such as Application Scenario file name, object repository name, function library name, test case list for execution, the data source, script development work area and script execution work area. Each application has a “Run” or “Ignore” flag against it to say which application scenario is to be executed. The Initialization VB Script (explained in the next section) uses this spreadsheet to decide the application & scenario to be executed, to get information about the Application Scenario file and do the initialization settings for an application.
The snapshot below shows how a sequence file looks.
The Sequence File (.xls file) is kept directly under the root directory.
3.6.    Initialization VB Script
The Initialization VB Script is the starting point of script execution. It launches QTP, sets the work area as development or production based on the user input and does the following settings to the Driver Script.

•    Set Work Area based on user input.
•    Set the application scenario file for the current run.
•    Set object repository.
•    Set function libraries.
•    Set data source.
•    Set the test case list.
After doing the above settings, it opens the Driver Script in read only mode for the user to start execution. With this, the control is passed on to the Driver Script.
The Initialization VB Script (.vbs file) is kept directly under the root directory.
Note: The significance of the Initialization VB Script is that it allows the user to run the same script to do the initialization settings for different web based applications.
3.7.    Driver Script
Driver script is a QTP test script which drives the script execution after taking control from the Initialization VB Script. Strictly speaking; this is the only script which is present as a QTP test script and not in the function library. As mentioned in section 3.1, this test script calls the function “ExecuteScenarioFile” which reads the keywords, objects and other parameters from the Scenario File and makes calls to appropriate functions in the function library. The beauty of this framework is that all the script execution is covered by a single test and single QTP action.
The Driver Script is kept directly under the root directory.
3.8.    Test Case List File
Test Case List File contains the list of Test Case Ids (explained in section 3.3 on Database) to be executed in the current run. As mentioned in section 3.3, this provides the user with the option to select only a subset of the data in the database for execution of the current run.
The Test Case List File is kept directly under the root directory.
4.    Tips on developing a Strong & Robust Automation Framework
The key to develop a strong & robust keyword driven automation framework is a challenge for any testing organization. To make this happen and realize the benefits of using it, the following guidelines are to be considered while developing the framework using the approach mentioned in this document.
•    Centralized Automation Team - One of the factors that stand out as a clear benefit in using this approach is the ability to reuse keyword components across applications thereby saving a lot of time, effort and cost. However, this calls for a lot of coordination between people doing automation in different projects. Therefore, it makes sense to have a centralized automation team working for different projects.
•    Coordination Between Function and Automation Teams – Though this approach provides the functional SMEs with more flexibility to design the business flow to create automated tests, the Automation Teams still need to work closely with the functional SMEs to make them understand what each keyword does, how the object names map with the logical names in the object repository and the database structure. This calls for good coordination between both the teams.
•    Creating right functions – The heart of the framework is the logic behind the functions in the function library. The way you design a function can make or break the whole framework. So, it is very important for the Automation Team to do proper analysis before creating functions. The endeavor should be to make the functions as generic as possible so that they can be reused across applications
•    Script Maintenance – Even though changes in the application can be taken care of by updating the application scenario spreadsheet, it would be a good practice for the Automation Team to make sure that all of their functions are still good for use. Though this may not be a huge effort as in traditional automation frameworks, it might call for some work here and there.


Donate:

Please Donate the some money (anything do you want) for my
blog if you beneficial for this, I will provide more real example for the
latest technique for whom who wants to make a carrier in IT field or solved
some problem, My Name is – RITESH KUMAR SINGH A/C number- 913010044116345 AXIS
Bank LTD :- Vaishali NCR, India-001
 

What are the various Automation Frameworks available? 1) Linear Scripting 2)The Test Library Architecture Framework. 3)The Data-Driven Testing Framework. 4)The Keyword-Driven or Table-Driven Testing Framework. 5)The Hybrid Test Automation Framework.



What is a Framework ?
Instead of providing a bookish definition of a framework, lets consider an example.
I am sure you have attended a seminar / lecture / conference where the participants was asked to observe the following  guidelines -
 ·            Participants should occupy their seat 5 minutes before start of lecture
·            Bring along a notebook and pen for note taking.
·            Read the abstract so you have an idea of what the presentation will be about.
·           Mobile Phones should be set on silent
·           Use the exit gates at opposite end to the speaker should you require to leave in middle of the lecture.
·           Questions will be taken at the end of the session
·         

Do you think you can conduct a seminar WITHOUT observing these guidelines????
The answer is a big YES! Certainly you can conduct a seminar / lecture / conference / demonstration without above guidelines (in fact some of us will not follow them even though there are laid  ... 

But if the guidelines are followed it will result in beneficial outcome like reduced audience distraction during lecture and increased participant retention and understanding of the subject matter.
Based on above, a Framework can be defined as a set of guidelines which when followed produce beneficial results.

Now what is a TEST Automation Framework ?
A set of guidelines like coding standards , test-data handling , object repository treatment  etc... which when followed during automation scripting produce beneficial outcomes like increase code re-usage ,  higher portability  , reduced script maintenance cost  etc. Mind you these are just guidelines and not rules; they are not mandatory and you can still script without following the guidelines. But you will miss out on the advantages of having a Framework.

What are the various Automation Frameworks available?
1) Linear Scripting
2)The Test Library Architecture Framework.
3)The Data-Driven Testing Framework.
4)The Keyword-Driven or Table-Driven Testing Framework.
5)The Hybrid Test Automation Framework.

Lets  look at them in detail -
1) Linear Scripting - Record & Playback
It is the simplest of all Frameworks and also know as "Record & Playback".In this Framework , Tester manually records each step ( Navigation and User Inputs), Inserts Checkpoints ( Validation Steps) in the first round . He then , Plays back the recorded script in the subsequent rounds.

Ex :  Consider logging into Flight Reservation Application and checking wether the application has loaded on successful log-on. Here , the tester will simply record the steps and add validation steps.

      SystemUtil.Run "flight4a.exe","","","open"
      Dialog("Login").WinEdit("Agent Name:").Set "Guru99"
      Dialog("Login").WinEdit("Password:").Set "Mercury"
      Dialog("Login").WinButton("OK").Click
      'Check Flight Reservation Window has loaded after successful log-on
      Window("Flight Reservation").Check CheckPoint("Flight Reservation")

Advantages
·         Fastest way to generate script
·         Automation expertise not required
·         Easiest way to learn the features of the Testing Tool

Disadvantages
·         Little reuse of scripts
·         Test data is hard coded into the script
·         Maintenance Nightmare
·          

 
2)The Test Library Architecture Framework.

It is also know as "Structured Scripting" or "Functional Decomposition".
In this Framework , test scripts are initially recorded by “Record & Playback” method. Later, common tasks inside the scripts are identified and grouped into Functions. These Functions are called by main test script called Driver in different ways to create test cases.
Ex:Using the same example as above, the function for logging in to Flight Reservation will look like .

      Function Login()
      SystemUtil.Run "flight4a.exe","","","open"
      Dialog("Login").WinEdit("Agent Name:").Set "Guru99"
      Dialog("Login").WinEdit("Password:").Set "Mercury"
      Dialog("Login").WinButton("OK").Click
      End Function

Now, you will call this function in the main script as follows
      'Driver Script
      Call Login()
      ---------------------------
      Other Function calls / Test Steps.
      ---------------------------

Advantages
·         Higher level of code reuse is achieved in Structured Scripting as compared to “Record & Playback”
·         The automation scripts are less costly to develop due to higher code re-use
·         Easier Script Maintenance

Disadvantages
·         Technical expertise is necessary to write  Scripts using Test Library Framework.
·         More time is needed to plan and prepare test scripts.
·         Test Data is hard coded within the scripts


3)The Data-Driven Testing Framework.
In this Framework , while Test case logic resides in Test Scripts, the Test Data is separated and kept outside the Test Scripts.Test Data is read from the external files (Excel Files, Text Files, CSV Files, ODBC Sources, DAO Objects, ADO Objects) and are loaded into the variables inside the Test Script. Variables are used both for Input values and for Verification values. Test Scripts themselves are prepared either using Linear Scripting  or Test Library Framework.

Ex: Developing the Flight Reservation Login script using this method will involve two steps.

Step 1) Create a Test - Data file which could be Excel , CSV , or any other database source.

AgentName
Password
Jimmy
Mercury
Tina
MERCURY
Bill
MerCURY

Step 2) Develop Test Script and make references to your Test- Data source.

      SystemUtil.Run "flight4a.exe","","","open"
      Dialog("Login").WinEdit("Agent Name:").Set DataTable("AgentName", dtGlobalSheet)
      Dialog("Login").WinEdit("Password:").Set DataTable("Password", dtGlobalSheet)
      Dialog("Login").WinButton("OK").Click
      'Check Flight Reservation Window has loaded
      Window("Flight Reservation").Check CheckPoint("Flight Reservation")
      **Note “dtGlobalSheet” is the default excel sheet provided by QTP.

Advantages
·         Changes to the Test Scripts do not affect the Test Data
·         Test Cases can be executed with multiple Sets of Data
·         A Variety of Test Scenarios can be executed by just varying the Test Data in the External Data File

DisAdvantages
·         More time is needed to plan and prepare both Test Scripts and Test Data
 4)The Keyword-Driven or Table-Driven Testing Framework.
The Keyword-Driven or Table-Driven framework requires the development of data tables and keywords, independent of the test automation tool used to execute them . Tests can be designed with or without the Application. In a keyword-driven test, the functionality of the application-under-test is documented in a table as well as in step-by-step instructions for each test.
There are 3 basis components of a Keyword Driven Framework viz. Keyword , Application Map , Component Function.

What is a Keyword ?
Keyword is an Action that can be performed on a GUI Component. Ex . For GUI Component Textbox some Keywords ( Action) would be InputText, VerifyValue, VerifyProperty and so on.

What is Application Map?
An Application Map Provides Named References for GUI Components. Application Maps are nothing but “Object Repositry

What is Component Function?
Component Functions are those functions that actively manipulate or interrogate GUI component. An example of a function would be click on web button with all error handling , enter data in a Web Edit with all error handling. Component functions could be application dependent or independent.

Ex: To understand Keyword View lets take the same example. It invovles 2 steps

Step 1: Creating Data Table (Different from Test-Data Table created in Data Driven Framework). This Data Table contains Action to be performed on GUI Objects and correspoding arguments if any. Each row respresents one Test Step.

Object
(Application MAP)
Action
(KEYWORDS)
Argument
WinEdit(Agent Name)
Set
Guru99
WinEdit(Password)
Set
Mercury
WinButton(OK)
Click

Window(Flight Reservation)
Verify
Exists


Step 2: Writing Code in the form of Component Functions.
Once you've created your data table(s), you simply write a program or a set of scripts that reads in each step, executes the step based on the keyword contained the Action field, performs error checking, and logs any relevant information. This program or set of scripts would look similar to the pseudo code below:

      Function main()
     {
                Call ConnectTable(Name of the Table) {   //Calling Function for connecting to the table.
                        while (Call TableParser() != -1)  //Calling function for Parsing and extracting values from the table.
                       {
                           Pass values to appropriate  COMPONENT functions. Like Set(Object Name , Argument) ex. Set( Agent Name , Guru99).
                       }
                }   
                      Call CloseConnection()   //Function for Closing connection after all the operation has been performed.
      }   //End of main

Thats all to Keyword Driven Framework.

The advantage of Keyword Driven Framework is that the Keywords are re-usable. To understand this consider  you want to verify login operation for a Website say YAHOO MAIL.  The table will look like this -

Object
(APPLICATION MAP)
   Action
(KEYWORD)
      Argument
WebEdit(UserName)
Set
WebEdit(Password)
Set
Xxxxx
WebButton(OK)
Click

Window(Yahoo Mail)
Verify
Loads

If you observe in this case the Keywords Set , Click , Verify remain the same for which corresponding component functions are already developed. All you need to do is change the Application Mapping (Object Repository) from earlier Flight Reservation to Yahoo Mail , with change in argument values and the same script will work!

Advantages
·         Provides high code re-usability
·         Test Tool Independent
·         Independent of Application Under Test, same script works for AUT (with some limitations)
·         Tests can be designed with or without AUT

Disadvantages
·         Initial investment being pretty high, the benefits of this can only be realized if the application is considerably big and the test scripts are to be maintained for quite a few years.
·         High Automation expertise is required to create the Keyword Driven Framework.


NOTE : Even though QTP advertises itself as KeyWord Driven Framework, you can not achieve complete test tool and application idependence using QTP.

5)The Hybrid Test Automation Framework.
As the name suggests this framework is the combination of one or more frameworks discussed above pulling from their strengths and trying to mitigate their weaknesses. This hybrid test automation framework is what most frameworks evolve into over time and multiple projects. Maximum industry uses Keyword Framework in combination of Function decomposition method.

PS:  Other Frameworks worth a mention are

1) Test Modularity Framework 
In this framework common task in test script are grouped together as Modules.
Ex:Using Actions in QTP use can create a Modualr Scripts
      ‘Sample Script for Login
      SystemUtil.Run "flight4a.exe","","","open"
      Dialog("Login").WinEdit("Agent Name:").Set "Guru99"
      Dialog("Login").WinEdit("Password:").Set "Mercury"
      Dialog("Login").WinButton("OK").Click
      ‘End of Script

Now you can call this Action in the main script as follows - 
      RunAction ("Login[Argument]", oneIteration)


2) Business Process Testing (BPT) -
This frameworks , breaks up large Business Processes into Components  which can re-used multiple times in the  same or different test scripts. For example , the Business Process of Booking a flight is split into components like Login , Finding Flights , Booking , Payment & Logout which can be re-used in the same  Business process or different processes. Also, BPT facilitates closer coordination amongst SME's and Automation Engineers . 
CLASSES AND OBJECT
Much like supername , the object has descended into our word, ready to flight the evilscontributing to the software crisis. Things weresimpler in the old days. You knew an object when you saw one,Now with all the newly acquired knowledge of objects and classes, you probably see objects even where there are none. So, what is the acid test? How can you be certain that something is inded an object?an object has state exhibits some well-defined behaviour, and has a unique identity.
Consider a pay phone where you put in a coin and then dial the number that you want a call.the pay phone exhibits a certain kind of behaviour that is when you drop a coin in and dial a number. It connects you to the person you want to talk to at the other end of line.The order in which the operations arecarried out is important.the pay phone behaves in this manner because of the existence of a state.one state of the pay phone is that of the coin inserted  by the caller but not usedthat is that is when the number has not yet been dialled.the state and behaviour together comprise the properties of an object .for example one property of the object pay phone could be the amount of money or the number of coins to be inserted.objects do not existes in isolation.