Sunday, March 6, 2011

LoadFunctionLibrary

LoadFunctionLibrary

1. Open a new test.
2. Open two new function libraries.
3. Save one function library as Add.qfl with contents as:

Function MY_ADD(a,b)
MY_ADD = a + b
End Function

Click on File -> Associate Library 'ADD.qfl' with Test.

4. Save second function library as MUL.qfl with contents as:

Function MY_MUL(a,b)
MY_MUL = a * b
End Function

5. In the test write:

Msgbox "Hello"
Msgbox (MY_ADD(2,3))

Run the test.

It should work fine and will show two message boxes, one with Hello and other with 5 (addition of 2 & 3).

6. Now in the test write (add one more line):

Msgbox "Hello"
Msgbox (MY_ADD(2,3))
Msgbox (MY_MUL(2,3))

Run the test.

It will show the first two message boxes fine, but displays an error in the third one.

7. Now in the test before the line that calls MY_MUL, add one more line, so now the final test looks like:

Msgbox "Hello"
Msgbox (MY_ADD(2,3))
LoadFunctionLibrary("C:\Program Files\HP\QuickTest Professional\Tests\MUL.qfl")
Msgbox (MY_MUL(2,3))

Now run the test, it should work fine.

You can associate function libraries with your test or load them dynamically (LoadFunctionLibrary) in your test.

Some important points related to LoadFunctionLibrary Statement:

There can be some maintenance issues by using LoadFunctionLibrary Statement because function library loaded via this statement is not shown in the Resources/Missing Resources panes, Comments tab in the QuickTest To Do pane or Dependencies tab in the QC and due to this the function library can be changed or deleted without anyone realizing that it is actually called by this test or component.

When the run session ends, function libraries that were dynamically loaded are unloaded.

If the function in the function library (associated) has same name as the function in the dynamically loaded library then the one in the dynamically loaded library will be used.