Function Definition Generator
Function Definition Generator
If you have repeatable steps in a test or an action then consider using a user defined function. User defined functions will make your tests look shorter, easier to maintain, read and design. Advantages of Function Library (functions) 1. Time and resources can be saved by implementing and using user defined reusable functions. 2. User defined functions can be stored in a function library or within an action in the test. 3. User defined functions can be registered as a method for a QTP test object If the function is stored in a function library then we have to associate that function library to a test. So that the test can call all the public functions listed in that library. Functions can be created manually or by using Function Definition Generator. It is easy to create a function library (Manual): Steps:
1.
2. Add content to it(That is we have to write body of the function here) 3. Open a new test
4.
Associate the function library with a new test (File Associate library with Test).
Creating the function Library through Function definition generator: Steps: 1. Open a new test.
2.
Open a new function library. Go to New Function library. (Now both new test and function library are open at the same time and we are in function library)
3.
4. In the Function Definition Generator window, type the name of the function as add. 5. In the Arguments area Click on + and type the name of first argument as a and again click on + and type the name of second argument as b and let the pass mode be the default which is By Value. 6. Click on OK to close that Function Definition Generator window.
7.
8. Now we have to write the function body(where it says TODO: ) as the following Public Function add (a, b) Sum = a+b
Msgbox Sum End Function 9. Save it (Save it by giving any name and extension either .qfl (by default) or .vbs or .txt)
10. Associate
11.
add 25,25 (i.e., the values for a and b) 12. Run the Test