Creating Object Methods

Applies to TestComplete 15.47, last modified on January 20, 2023

Script extensions allows you to create custom runtime objects that will be incorporated into the TestComplete object model. This topic explains how to write the source code of a custom object’s methods.

To create an object’s method code, simple write a routine that implements this method. The routine must have the same number of parameters as the method is supposed to have. If the method is supposed to return a value, the routine should return a value (that is, it should be a function).

In the general case, the routine’s name may not coincide with the object’s method name -- it is the script extension’s description.xml file that maps the runtime object’s methods to the corresponding script routines. However, it is recommended that you give the routine the same name as the method, the ObjectName_MethodName or similar name. This way, you can simplify the understandability and maintenance of the object’s source code.

The example below demonstrates the source code of two sample methods, one having no parameters and another one having one parameter:

JScript

// script.js

function LogMessage()
{
  Log.Message("Hello, world!");
}

function LogMessageEx(Text)
{
  Log.Message(Text);
}

VBScript

' script.vbs

Sub LogMessage
  Log.Message "Hello, world!"
End Sub

Sub LogMessageEx (Text)
  Log.Message Text
End Sub

See Also

Script Extensions
Creating Script Extensions
Creating Runtime Objects
Creating Object Properties

Highlight search results