UFT Functions
UFT Basics

UFT Classes #11: Introduction to Functions

If you have segments of code that you need to use several times in your tests, you may want to create a function and then call that function from within the main action. Say you want to display a message box repeatedly >> Just create a function and reuse it every time. By using functions, tests are shorter, easier to design, read and maintain.

Function Demo

MsgBox “This is a Test Function”

End Function

Please note UFT has some built-in functions and methods that might help testers during test. But there can be a situation where user performs some important task that is not available by default. In this case, we can create a user-defined function and save it in a function library file to re-use.

General Steps: Create New Function Library >> Write Function Code >> Save >> Associate Function library with your test >> Call the function within your test as many times as required.

  • A Function Library can contain multiple functions, sub procedures or modules
  • Associating a function library with a test permits user to call any of the functions in the function library from that test.
  1. New >> New Function Library. The New Function Library dialog box opens.

2. In the New Function Library dialog box, first create a new folder

3. Inside a new folder, create a new Function Library by giving a Name

4. Click on “Create”. (.qfl)

5. To open function library in the document pane of the UFT window, go to File > Open > Function Library. A blank function library opens in the document pane.

6. Write the function in UFT editor pane

7. Save the function by clicking on ‘Save’ button.

8. After saving the function library, close it by clicking on File > Close.

To associate the function library with your Test >> Open the Solution Explorer window, if it is not opened by going to View > Solution Explorer or Solution Explorer button >> In the Solution Explorer window, right-click the test and select Add > Associate Function Library.

Function library is associated with the test!

Save the test by clicking on “Save” button.

Save

Leave a Reply

Your email address will not be published. Required fields are marked *