Labels

Saturday 15 September 2012

QTP - Actions Vs Functions

Dear Friends,



In most of the QTP interviews, you will get this question: What is the difference between Actions and Functions.

Few interviewers will be satisfied, when you say 
- Actions are only available in QTP whereas Functions are available in both QTP and VBScript.
- Each action would have its own Object repository and Data table whereas Function does have it.

And if you go further and explains below points, I am sure you will get 100/100 :-)
- When parameters are used in actions, input parameters should be defined first and then followed by output parameters.
- A same parameter cannot be used for both input and output purposes whereas in function we can use it
- An array or object cannot be a parameter for Actions

BTW, don't forget the commonalities between Actions and Functions :
- Both are mainly used to increase the re-usability and helps to divide your tests into logical units or business processes
- Both are optionally accepts input and output parameters

Example:
Write a Function which returns more than one value in VBScript/QTP

Public Function myNumbers ()
   Dim arr(2)
   arr(0) =10
   arr(1) = 20
   myNumbers = arr
End Function

x = myNumbers()
print x(0)
print x(1)


P.S: This is my first write up in online blog, So I would like to get your feedback. Feel free to post your comments.Thanks




Book reference: "QTP Unplugged - By Tarun Lalwani"

1 comment: