Creating Operation Initialization Routine

Applies to TestComplete 14.91, last modified on July 20, 2021

Custom keyword test operations created with script extensions can have initialization routines, which serve as operation constructors. The initialization routine is called when TestComplete creates a new instance of the operation. This happens when the user adds the operation to their test, when TestComplete records the operation, and so on. Initialization routines are usually used to perform some preliminary actions, for example, specify default values of operation parameters and fields.

To create the initialization routine for an operation, you need to do the following:

  • Write the routine code. The routine should have the Data and Parameters arguments, which specify the objects providing access to the operation’s fields and parameters, respectively. (See the event description for details.) At that, if the routine has only parameters or both fields and parameters, both Data and Parameters arguments are required. If the operation has only fields or neither fields nor parameters, the routine must have the Data argument only.

  • Subscribe to the operation’s OnCreate event in the description.xml file and specify the routine name as the event handler.

The following example provides the code of a sample initialization routine for an operation that has the Description field and the SourceFileName, Destination and RenameOnCollision parameters.


    <Category Name="Keyword Test Operations">
        <ScriptExtension Name="Copy File Operation" Author="SmartBear Software" Version="1.0">
            <Script Name="">    <!-- Specify the script file name here -->

                <KDTOperation Name="Copy File">
                        <Field Name="Description" />
                        <Parameter Name="Source" />
                        <Parameter Name="Destination" />
                        <Parameter Name="RenameOnCollision" />
                        <Column Name="Item" Value="Copy File" />
                        <Column Name="Value" Editable="True" EditorType="Parameters" />
                        <Column Name="Description" GetValue="CopyFile_GetDescription" />
                        <Event Name="OnCreate" Routine="CopyFile_OnCreate" />



// The operation's initialization routine
function CopyFile_OnCreate(Data, Parameters)
  Data.Description = "Copies a file to a new location.";

  Parameters.Source = "";
  Parameters.Destination = "";
  Parameters.RenameOnCollision = true;

// Returns the text to be displayed in the Description column of the Keyword Test editor
function CopyFile_GetDescription(Data)
  return Data.Description;


' The operation's initialization routine
Sub CopyFile_OnCreate(Data, Parameters)
  Data.Description = "Copies a file to a new location."

  Parameters.Source = ""
  Parameters.Destination = ""
  Parameters.RenameOnCollision = True
End Sub

' Returns the text to be displayed in the Description column of the Keyword Test editor
Function CopyFile_GetDescription(Data)
  CopyFile_GetDescription = Data.Description
End Function

Note, that instead of creating the initialization routine, you can specify the default values for operation parameters and fields in the description.xml file. You can do this using the DefaultValue attribute of the Parameter and Field elements. However, this approach has one specific: the default values are treated as strings. So, if some parameters or fields are actually of boolean or numeric types, you may need to perform type conversion in the operation code.

If default values for operation’s parameters and fields are specified both in the description.xml file and in the initialization routine, the latter will overwrite the values specified in the description file.

See Also

Creating Keyword Test Operations
Creating Keyword Test Operations - Basic Concepts
Creating Operation Parameters and Fields
Writing Operation Code
Creating the Operation Setup Routine
Structure of the Description File

Highlight search results