Defining a New Method for a Single GUI Object

To define a new method to use on a single GUI object, not for an entire class of objects, you add the method definition to the window declaration for the individual object, not to the class. The syntax is exactly the same as when you define a method for a class.

To add a method to a single GUI object, for example to add the SelectAll() method to a specific TextField object, locate the GUI object in your frame.inc file, like described in the following code sample:
window MainWin UntitledNotepad

  ...

  TextField TextField
    locator "//TextField"
In your test cases, you can then use the SelectAll method like any other method of the TextField object:
window MainWin UntitledNotepad

  ...

  TextField TextField
    locator "//TextField"
    SelectAll()
      TypeKeys("<Ctrl+a>")
Note: Adding a method to a single GUI object adds the method only to the specific GUI object and not to other instances of the class.

Classic Agent Example

For example, suppose you want to create a method named SetLineNum for a dialog box named GotoLine, which performs the following actions:

  • Invokes the dialog box.
  • Enters a line number.
  • Clicks OK.

The following 4Test code shows how to add the definition for the SetLineNum method to the declaration of the GotoLine dialog box.

window DialogBox GotoLine
   tag "Goto Line"
   parent TextEditor
   const wInvoke = TextEditor.Search.GotoLine

   void SetLineNum (STRING sLine)
     Invoke ()            // open dialog
     Line.SetText (sLine) // populate text field
                          // whose identifier is Line
     Accept ()            // close dialog, accept values
     
     //Then, to go to line 7 in the dialog, you use this method call in your testcases:
     GotoLine.SetLineNum (7)