Wednesday 14 December 2011

Environment Variables in QTP

QTP Environment variables are special type of variables whose values persist across and are shared by all actions in a test. QTP environment variables can be used to share information across actions,recovery scenarios and libraries.

There are 3 types of environment variables:

1)Built-in: QTP provides a variety of environment variables that define information such as the currently executing test name,the test's path,operating system,its version etc..

Steps to verify the availability of built-in environment variables

>Go to File-->Settings-->Environment-->Built-in

Accessing an Built-in environment variable in Expert View

Msgbox Environment.Value("ProductDir") 'It will  show the folder path where the product is installed'

Msgbox Environment.Value("ActionName") 'It will indicate which action is currently running'

2)User defined internal: These variables are defined in a test and saved with the test.These variables can be modified during run time.


Steps to create an user defined internal environment variable

>Go to File-->Settings-->Environment-->Select User-defined from variable Type drop down List

>Click on add icon ('+')
>Add New Environment Parameter Opens
>Provide some values in Name field(say 'x') and in value field (say '10')
>Click OK.
>Now Click OK on Test Settings Tab.

Accessing an User-defined internal environment variable in Expert View

Msgbox Environment.Value("X") 'It will display the value which we have given in value field i,e 10'

3)User-defined external: These variables are defined in an external environment file.These variables  are read-Only and cannot be modified during run-time.The external file can be associated with with the test and can also be loaded at run time using LoadFromFile method.


Create  an XML File

<Environment>
       <Variable>
              <Name>Address1</Name>
              <Value>BBSR</Value>
       </Variable>
       <Variable>
              <Name>Address2</Name>
              <Value>Delhi</Value>
       </Variable>
       </Environment>

Steps to Create an user defined external environment variable

>Create an XML file and Save the file in a location that is accessible from the Quick Test.
>Go to File-->Settings-->Environment-->Select User-defined from variable Type drop down List
>Select the 'Load Variables and values from external file' Check box.
>Use the browse button or enter the full path of the XML file .
>The variables defined in the selected file are displayed in blue colour in the list of user-defined
   environment variables with its Type as External.
>Click OK on Test Settings Tab.

Accessing an User-defined External environment variable in Expert View

Msgbox Environment.Value("Name") 'It will display the value which we have provided for the environment variable Name'

Thursday 1 December 2011

Data Table

      Data Table
---------------------------------------------

It is  nothing but a type of excel  sheet with columns and rows which shows the data in the data table related to the test. This helps in parameterizing the test.

    Data Table Object Model
----------------------------------------------
    
 Data Table      :    Represents the global and all local sheets
 Dtsheet          :    Represent single sheet in test
 Dtparameter  :    Represents single column in the sheet.


    Types of data tables 
----------------------------------------------
  
 Design time      :     It is Created before the test is run.
 Run time          :     It is generated after execution of test.

    Types of sheets in data table
-----------------------------------------------

Global Sheet : It is used for storing the data used for Test Iteration .If there are more number of action in a test, then use of global sheet will be better and easier to pass the values and which is visible to all the actions
             
Local Sheet : It is used for storing the data related to corresponding Action iteration. Here actions run only one iteration.In local Sheet it is relevant to only particular action which is used .It is visible to its respective action.


   Parameterization of Data table
-------------------------------------------------
 The first thing to know is, How  to retrieve data from Data table

 - - To retrieve data from Local Sheet :-

DataTable("ColumnName", dtLocalSheet)

 - - To retrieve data from Global Sheet :-

DataTable("ColumnName", dtGlobalSheet)

 - - To retrieve the data from one action to another action :-

DataTable.GetSheet("Action  Name").GetParameter("Column Name").ValueByRow(Row number from where the data to be taken)

    Import and Export Method in DataTable
-------------------------------------------------------------
Methods for Import and Export of Data table From a .xls file

--   Import method : This method is used to import an entire workbook into QTP data table.
             
Ex:  datatable.Import "Give the relative path where the xls file is stored in system"

datatable.Import "\\Filename.xls"

 --  Export method : This method is used to export the entire data tables from QTP to an .xls file.
               
Ex:  datatable.Export "Give the relative path where the xls file is stored in system"              

datatable.export "\\Filename.xls"

 --   ImportSheet method : This method is used to import only a specific sheet into QTP datatable.
               
 Ex :  datatable.ImportSheet "Give the relative path where the xls file is stored in system",1,2

[ (1)Imports the source sheet and  (2) to destination sheet] 
          
 datatable.ImportSheet "\\Filename.xls",1,2

 --   ExportSheet method : This method is used to export only a specific datatable sheet from QTP to an .xls file.
              
Ex :  datatable.ExportSheet "Give the relative path where the xls file is stored in system",1

[  Exports the specified sheet to a file; Overwrites by default, only one copy is exported. ] 
             
datatable.ExportSheet "\\Filename.xls",1

Tuesday 29 November 2011

Introduction to QTP

QTP
-----
It is Quick Test Professional often referred  as Quick Test which is a functional automation tool Created
by HP subsidiary Mercury Interactive that allows the automation of user actions on web or desktop application.

Generally it uses VB script to manipulate with the objects.VB Script functionality is available in the QTP Expert View.

QTP has two modes in which we can edit and view a test script

a)Keyword View
b)Expert View

Keyword View
----------------
It displays the script in the form of keywords arranged in a tree format.

Expert View
------------
It gives us a clear picture about the Vb script code .

Features of QTP
----------------

a)Record and Playback feature can be easily implemented .

b)Run time Checking of application objects and Data using various check points.

c)It Supports both Data Driven testing and Keyword Driven Testing features .

d)Easy and effective programming using Vb Script in Expert view. etc.

e)It can handle errors in a proper manner through recovery scenario.

f)It Supports XML,excel for inputting data and for exporting our results.

Supported Technologies:
------------------------

Web,Java,.Net,SAP,Oracle,Siebel,People Soft,Delphi,Flex etc..

QTP Versions
-------------

11.0 - Released in 2010 (Latest Version)
10.0 - Released in 2009
9.5 -  Released in 2008
9.2 -  Released in 2007
9.1 -  Released in 2007
9.0 -  Released in 2006
8.2 -  Released in 2005
8.0 -  Released in 2004
7.0 -  Never released.
6.5 -  Released in 2003
6.0 -  Released in 2002
5.5 -  First release. Released in 2001

Automation Process in QTP
--------------------------
--Analyse the Application.
--Create Object Repository(OR).
--Create Test Script..
--Run test Script
--Analyse Results.

Drawbacks of QTP
-----------------
a)It does not support Usability Testing

b)Cost for License is  high.

c)It Cannot run multiple threads at a time.

Wednesday 23 November 2011

How QTP Recognises Objects

Before going to the details of how QTP recognises an Object, let's have a brief idea about what an Object is. As we have covered (with the assumption of all have covered) Object Oriented Programming Concept(OOPS), all must have known that an Object is a run time entity (though all must have jaded with this definition) which has a physical existence. Same applies to QTP Objects. Some examples of QTP objects for let say a web application may be Check Box,Radio Button,Web Button,Combo Box etc.

There are two types of object in QTP such as Test Objects and Run Time Objects. Test Objects are those objects which are stored in the repository during a recording session. All the properties (along with their values) associated with an object are stored during recording session in the object repository. Properties of an object may be, for instance Name, Title, Value, HTML Tag etc. Run Time Objects, on the other hand are the actuals objects in the application which QTP encounters during a run session on which methods are performed. Property values of a Test Object are matched with the Propery values of the corresponding Run Time to identify an Object.

For each object class, QuickTest learns a set of properties when it records and it uses this description to identify the object when it runs the test. For example, by default, QTP learns the HTML Tag, Name, and Type of each Web Button on which we record an operation. If the above three Mandatory properties values are not sufficient to uniquely identify the Web Button within its parent object, QuickTest adds some assistive properties and/or an ordinal identifier to create a unique description. Assistive property for the Web Button may be Value, Innertext, Outertext etc. An ordinal identifier may be the Index or Location.

Now, for explaining how QTP recognises an object having some of its properties values stored in the repository, let us correlate how we human being recognise a person we have met before. Suppose you have met Mr. X some years ago. At that time you had marked some of his physical appearance or structure like his approximate height, complexion, eye color, hair style, voice, facial appearance etc. Here your gray matter works as the repository where you stored all the attributes of Mr. X. Now if you have to identify Mr. X from a group of say 50 people, you will try to recall all the attributes that you have marked during your previous meeting. Since you are meeting after a long gap, Mr. X might have lost all his hair and hence you cann't identify him by just recalling his hair style or there may be more than one person whose height and complexion match with that of Mr. X and hence it is diffucult for you to recognise him by the attribute height and complexion. But now, atleast you have a rough idea about who may be Mr. X among 50 people, though you are not sure. When you recall his facial appearance and listen to his voice you are able to recognise Mr. X easily.

This is what exactly happens when QTP has to recognise an object. It reads the property values stored in the repository, and tries to identify it. If QTP does not able to identify an object by the property values stored in the repository, it invokes a mechanism called Smart Identification Mechanism (SIM) which further checks with some more properties values. If still it can not identify the object, it throws an error saying Object can not be identified.