Tuesday, July 8, 2008

QTP Actions Vs Functions

ActionsFunctions
An action can have object repository associated with it. Functions do not use object repository.
You can select one of the following data types as parameter for actions:
  1. String,
  2. Boolean,
  3. Date,
  4. Number,
  5. Password and
  6. Any.
Functions can accept arrays, objects and even another function calls etc. as Parameters.

Example of “function call” as an argument:

Function myfunction2(argument1,argument2)
d=argument1 - argument2
myfunction2=d
End Function
Function myfunction(argument1,argument2)
c=argument1 + argument2
myfunction=c
End Function
a = myfunction (myfunction2(5,2),3)
msgbox a
Each time you add a new action to the test, a new action sheet is added to the Data Table. An action consists of its own test script, including all of the steps recorded in that action, and any objects in its local object repository.
Each action has its folder containing Script file, snapshots folder (if any), Object Repository file and much more.
Function only has its code associated with it and nothing else.
There are three kinds of actions:
Non-reusable action
Reusable action
External action

VBScript has two kinds of procedures; the Sub procedure and the Function procedure. Of course there are built-in functions also like Date, Len, and InStr etc.