Programming in the Editor and function libraries

Relevant for: GUI tests and components

Can I store functions and subroutines in a function library?

You can create function libraries to hold your function and then call the functions from any test action or component by associating them with the test or with the component's application area. You can also register your functions as methods for UFT One test objects. Your registered methods override the functionality of an existing test object method for the duration of a run session, or you can register a new method for a test object class.

For more details, see User-Defined Functions.

Back to top

How can I enter information during a run session?

The VBScript InputBox function enables you to display a dialog box that prompts the user for input, and then continues running the test or component. You can use the value that was entered by the user later in the run session. For details on the InputBox function, see the VBScript Reference. For example:

Browser("Advantage Shopping").Page("Advantage Shopping").WebEdit("username").Set "ADVAN"
Dim Message
Message = "Enter password"
Password = InputBox(Message)
Browser("Advantage Shopping").Page("Advantage Shopping").WebEdit("password").SetSecure Password

Back to top

I have a Microsoft Access database that contains data I would like to use in my test. How do I do this?

The Editor enables you to access databases using ADO and ODBC. Below is a sample test that searches for books written by an author in the "Authors" table of the database.

Dim MyDB
Dim MyEng
Set MyEng = CreateObject("DAO.DBEngine.35")
Dim Td
Dim rs
' Specify the database to use.
Set MyDB = MyEng.OpenDatabase("BIBLIO.MDB")
' Read and use the name of the first 10 authors.
Set Td = MyDB.TableDefs("Authors")
Set rs = Td.OpenRecordset
For i = 1 To 10
    Browser("Book Club").Page("Search Books").WebEdit("Author Name").Set rs("Author")
    Browser("Book Club").Page("Search Books").WebButton("Search").Click

Back to top

How do I customize the run results?

You can add information to the run results by using the ReportEvent method to add an event to the Run Results Viewer-based report or the AddRunInformation or ReportHtmlEvent methods to add an event to the HTML report. This adds a step to the run results containing a free-text message and a step status that can potentially affect the status of the run session. The step can also include an image, such as a logo, if you specify an image file path.

You can also add custom report statements using the Insert Report dialog box.

For more details, see the Reporter object in the Utility Objects section of the UFT One Object Model Reference for GUI Testing.

Back to top

See also: