Verify the code works when it is not within a function. If the code does not work when it is not in a function in a QuickTest Professional (QTP) script or within a pure VBS script (while QuickTest Professional is not in use), it will not work when it is placed within a function. The following example shows the step by step process of debugging a simple function.
Example:
(Optional) Move the function into a function library.
If function is returning a value, the value should be assigned to the function name. This is a VBScript requirement.
Example:
Function examplefunc
examplefunc = "returned value"
End Function
msgbox examplefunc
If function is saved in an external function library, make sure it associate the function library with the test script.
Example:
Function ex_func(obj, txt)To debug the above function (which has intentional typos), copy the statements into a QuickTest Professional script:
msgbxo obj.Exist
msgboxx txt
End Function
msgbxo obj.ExistIf needed, modify any references to a generic object to an actual object:
msgboxx txt
msgbxo Browser("Browser").ExistExecute the code; debug as needed:
msgboxx txt
msgbox Browser("Browser").Exist ' corrected typo: msgbxo -> msgboxCopy the corrected code into the function. Verify it works as expected:
msgbox txt ' corrected typo: msgboxx –> msgbox
Function ex_func(obj, txt)If needed, modify references to specific objects back to general references:
msgbox Browser("Browser").Exist
msgbox txt
End Function
Function ex_func(obj, txt)Verify the function works as expected.
msgbox obj.Exist
msgbox txt
End Function
(Optional) Move the function into a function library.
If function is returning a value, the value should be assigned to the function name. This is a VBScript requirement.
Example:
Function examplefunc
examplefunc = "returned value"
End Function
msgbox examplefunc
If function is saved in an external function library, make sure it associate the function library with the test script.