How to Create, Modify and Delete Methods

Applies to TestComplete 15.44, last modified on November 10, 2022

The object-driven testing (ODT) functionality is deprecated. Do not use it to create new tests. It will be removed from the product in one of the future releases. As an alternative, you can create custom classes in your scripts. For more information, see Alternatives to the ODT functionality.

You can create, modify and add methods both to classes and to objects. We would like to draw your attention to the following principles used when working with methods:

  • When you add a method to a class, the method is also added to all objects that are based on this class. When you add a method to an object, it is added to this object only.

  • Each method contains two properties: method name and the script routine that will be used as an object method. The method name is displayed in the Name column of the Methods page of the ODT, Classes or Data editor; the name of the script procedure is displayed in the Value column of this page.

  • For methods that belong to objects, you can specify script routines other than those specified for methods in the classes, on which the objects are based. This gives you an opportunity, to create objects containing methods that have the same name, but perform different operations.

  • To refer to the object instance that the given method belongs to in the routine code, use the keyword Self in DelphiScript or This in VBScript, JScript, C++Script or C#Script (note the first capital).

  • When you rename a method in a class, the method is also renamed in all objects that are based on this class. A similar principle is used for script routine names: if you modify the script routine name for a method in a class, this name is modified in all objects, which are based on this class, on conditions that you have not modified the name since the object creation.

  • Method names must match the naming rules of the project scripting language. For information on this, see below.

  • All methods are public.

To add a new method to a class or object

  1. If you want to add a new method to a class, select the class in the ODT | Classes branch of the ODT editor or in the Classes tree of the Classes editor. If you want to add a new method to an object, select the object in the object hierarchy displayed in the ODT | Data branch of the ODT editor or in the Data tree of the Data editor.

  2. Switch to the Methods page.

  3. Right-click somewhere in the page and select New Item from the context menu.

  4. TestComplete will create a new method and give it a simple name like NewMethod1 (If you create a method for a certain object, the default method name is NewObjectMethod1). You can then rename the method and specify a script routine for it. If the method belongs to a class, you may not specify a script routine for it. In this case, you need to specify a script routine in objects that are based on this class.

Names of methods are used for referring to methods in scripts and keyword tests. That is why these names must consist of the A..Z, a..z, 0..9 and _ characters only (that is, they must be valid identifiers in the scripting language you use). The method names are case-sensitive in JScript, C++Script and C#Script scripts, and case-insensitive in VBScript and DelphiScript scripts.

To rename a method

  1. If you want to rename the desired method in the class to which it belongs, select the class in the ODT | Classes branch of the ODT editor or in the Classes tree of the Classes editor. If you want to rename the desired method in the object it belongs to, select the object in the object hierarchy displayed in the ODT | Data branch of the ODT editor or in the Data tree of the Data editor.

  2. Switch to the Methods page.

  3. Right-click the desired method and select Rename from the context menu.

  4. Specify the desired method name.

  5. Press Enter or click somewhere out of the in-place editor to apply your changes. Press Esc to cancel the changes.

To specify a script routine for a method

  1. If you want to specify a script routine for the desired method in the class to which it belongs, select the class in the ODT | Classes branch of the ODT editor or in the Classes tree of the Classes editor. If you want to specify a script routine for the desired method in the object it belongs to, select the object in the object hierarchy displayed in the ODT | Data branch of the ODT editor or in the Data tree of the Data editor.

  2. Switch to the Methods page.

  3. Right-click the desired method and select Edit from the context menu.

  4. In the Test Procedure column specify the script routine name in the following format:

    unit_name.routine_name

    Both unit_name and routine_name are required.

    You can also click the ellipsis button and select the desired procedure with the ensuing Select Test dialog.

To copy and paste a method

Methods can be copied two ways: explicitly or implicitly. When you switch to the Methods page, you may copy or paste by calling the corresponding commands from a context menu.

To copy a method within the Methods page:

  • Select the desired method in the editor and click on the Edit toolbar.

To paste a method within the Methods page:

  • Click on the Edit toolbar.

These commands only affect methods of the current class/object. You cannot copy a method from another class or object. Nevertheless, it can be done implicitly while copying the class or object, as it is copied along with its properties and methods. This technique works well when copying classes/objects within the same project, but could lead to a malfunction when the class/object is taken from another project, since the method routine from the source project cannot be found in target project. To avoid this, you should redefine the routine used by the method or copy its code from the source project.

To enable or disable the method execution

When you create an object of an ODT class, its methods are disabled by default and thus are not executed during the test run. Whether a method is enabled or disabled is controlled by the check box next to the method name. Enabled methods have two run modes: either before or after all methods of the object’s child objects.

To make the method run before all methods of the object’s child objects are called:

  • Click the checkbox next to the method name until the check mark becomes .

To make the method run after all methods of the object’s child objects have been called:

  • Click the checkbox next to the method name until the check mark becomes .

To disable the method execution:

  • Clear the check box next to the method name.

To change the method execution order

Objects created with the ODT project item are organized in a tree-like structure. When walking down the object tree, TestComplete executes methods of these objects (see Controlling Object-Driven Tests). You can change the method execution order by changing their position in the list and also specifying whether they will be called before or after the child objects’ methods.

To change the method’s position:

  • Right-click the method in the list and choose Move Up or Move Down from the context menu.

Note: Besides methods inherited from a class, an object can also have its own methods. These specific methods are always listed and executed after methods provided by the class. Specific methods can be rearranged among themselves, but cannot be mixed with the class methods.

To delete a method

  1. If you want to delete the desired method from the class to which it belongs, select the class in the ODT | Classes branch of the ODT editor or in the Classes tree of the Classes editor. If you want to delete the desired method from the object it belongs to, select the object in the object hierarchy displayed in the ODT | Data branch of the ODT editor or in the Data tree of the Data editor.

  2. Switch to the Methods page.

  3. Right-click the desired method and select Delete from the context menu.

  4. TestComplete will display a message box asking you if you want to delete the selected method. Click OK to delete the method, or Cancel to cancel the deletion.

Note: When you delete a method from a class, it is deleted from all objects that are based on the class.

See Also

Object-Driven Testing
ODT Editor
Classes Editor
How to Create, Modify and Delete Properties

Highlight search results