We can create function libraries in QTP and call their functions from an action in our test. A function library is a separate QTP document containing VBscript functions, subroutines, modules, and so forth. Each function library opens in a separate window, enabling us to open and work on one or several function libraries at the same time. After you finish editing a function library, you can close it, leaving your QTP session open. You can also close all open function libraries simultaneously.
By implementing user-defined functions in function libraries and associating them with your test, you and other users can choose functions that perform complex operations, such as adding if/then statements and loops to test steps, or working with utility objects—without adding the code directly to the test. In addition, you save time and resources by implementing and using reusable functions.
QTP provides tools that enable you to edit and debug any function library, even if it was created using an external editor. For example, QTP can check the syntax of your functions, and the function library window provides the same editing features that are available in the Expert View.
Example:
Function val_from_excel(epath, esheet, erow, ecolumn)
Set exlApp = CreateObject("Excel.Application")
exlApp.WorkBooks.Open (epath)
Set my_sheet = exlApp.Sheets.Item(esheet)
value = my_sheet.Cells(erow, ecolumn)
exlApp.quit
Set exlApp = Nothing
msgbox value
'msgbox val_from_excel
End Function
call val_from_excel("C:\Test1.xls", "Sheet1", 3,3)
No comments:
Post a Comment