Sunday, January 27, 2008

Function Library Example 1

QTP Function Library - Example 1

1. Open a new test. Go to File->New->Test.

2. Open a new function library. Go to File->New->Function library.
(Now both new test and function library are open at the same time and we are in function library.)

3. Go to Insert->Function Definition Generator.

4. In the Function Definition Generator window, type the name of the function as my_sum.

5. In the Arguments area click on ‘+’ and type the name of first argument as ‘var1’ and again click on ‘+’ and type the name of second argument as ‘var2’ and let the Pass Mode be the default which is ‘By Value’.

6. In Additional Information area, enter the Description as ‘addition function’. Let the ‘Documentation’ be empty. Click on Ok to close that Function Definition Generator window.

7. Now it will add the function to your already open Library.

8. Now we have to write the function body (where it says TODO:)

9. Finally it will look like:

'@Description addition function
Public Function my_sum(var1, var2)
sum=var1+var2
msgbox sum
End Function

10. Save it. (Save it by giving any name and extension either .qfl (by default) or .vbs or .txt)

11. Associate it. (File-> Associate Library with Test)

12. In expert view of Associated test type:

my_sum 1, 2


Also See:

QTP Function Library
QTP Function Library - Example 2
QTP Function Library - Example 3
QTP Function Library - Example 4
ExecuteFile