What is the Basic difference between
the Actions and Functions in QTP.
- In QTP and Action both provides code modularity , And you can perform all the same things with Functions as you are able to do with actions.
– But Action can contains
Object Repository, Data table, Active screen etc. whereas function do
not have these features.
– Action can be made
Reusable / Non-Reusable as per need, where as Functions are written
for
their re-usability only.
– Action is internal to QTP
whereas Function is just lines of code with some/none parameters and
and a single return vale.(
Can also return an array too)
--- But as per time complexity
Function works faster than its respective action. Having a single
script that just calls
multiple function appears to load and run faster than having a script
that
calls multiple actions for
performing the same intended thing.
--- Action Parameter have
default values (From Action whereas VB script function do not have
any
default values.
---- In my opinion , Action is
mainly for navigation purpose and field entries where as Functions
are for checking
validation for specific fields. For example , with the help of
fuction we can we
verify in the date field
(WebEdit) entered date is in what Format(MMDDYY orDDMMYY)
and it can be reused for
all the date fields present in the application . There is no need to
write
same code multiple times
in the action.
How To define a Function and
Call it :
Function Testfunction()
Print "Function test"
End Function
Print "Function test"
End Function
Function TestDemo(a,b)
myfunction2=a+b
'assign value to function name
End Function
Call Function::--
Call Testfunction() 'calling 1st function, without any return value
Call Testfunction() 'calling 1st function, without any return value
Store=TestDemo(argument1,argument2) 'calling 2nd function, with a return value
the Function TestDemo returns a value that will be stored in the variable "abc". :
---- There is big disadvantage
of using function is that partially from the library ("Run from
step" option is not available) you are not allowed to run it
partially while action can be executed from any step. This can make a
significant difference for developing and maintaining of test
scripts.
Function libraries should only be used as auxiliary resources, not as main script drivers. A function library should only contain code that repeats often in your tests (counters, reading values from a table, waiting for a browser to load etc.). Something to be done instead of typing that piece of code over and over again.
Function libraries should only be used as auxiliary resources, not as main script drivers. A function library should only contain code that repeats often in your tests (counters, reading values from a table, waiting for a browser to load etc.). Something to be done instead of typing that piece of code over and over again.