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