CodeEditor Object

Applies to TestComplete 15.63, last modified on April 10, 2024


The CodeEditor object provides access to the TestComplete Code Editor from script extensions. The object provides properties that let you obtain or modify the code in the active Code Editor instance and determine the text that is currently selected.

Note: The CodeEditor object can only be used in the script extension code. It does not exist in TestComplete scripts.



The following example demonstrates how to use the CodeEditor object to insert the Log.Message method call to the code displayed in the Code Editor panel:


function InsertLogMessage()
  var oMethodCall = Syntax.CreateInvoke();
  oMethodCall.ClassValue = "Log";
  oMethodCall.InvokeName = "Message";
  oMethodCall.IsProperty = false;
  oMethodCall.AddParameter("Hello, world!");

  var strCode = Syntax.GenerateSource(oMethodCall) + "\r\n";

  if (CodeEditor.IsEditorActive)
    if (CodeEditor.CursorPos == CodeEditor.Text.length)
      CodeEditor.Text += strCode;
      CodeEditor.Text = aqString.Insert(CodeEditor.Text, strCode, CodeEditor.CursorPos);


Sub InsertLogMessage
  Dim oMethodCall, strCode

  Set oMethodCall = Syntax.CreateInvoke
  oMethodCall.ClassValue = "Log"
  oMethodCall.InvokeName = "Message"
  oMethodCall.IsProperty = False
  oMethodCall.AddParameter "Hello, world!"

  strCode = Syntax.GenerateSource(oMethodCall) & vbNewLine

  If CodeEditor.IsEditorActive Then
    If CodeEditor.CursorPos = Len(CodeEditor.Text) Then
      CodeEditor.Text = CodeEditor.Text & strCode
      CodeEditor.Text = aqString.Insert(CodeEditor.Text, strCode, CodeEditor.CursorPos)
    End If
  End If
End Sub

See Also

Script Extensions
Working With the Code Editor
Code Editor - Overview

Highlight search results