Using Generated Code

Applies to TestComplete 15.42, last modified on August 01, 2022

The way in which custom actions can use the generated script code depends on the action type: record-time or design-time.

Record-time actions can use the Recorder.AddTextToScript method to insert the generated code into the script being recorded:

JScript

var strCode;

// Generate code
...

Recorder.AddTextToScript(strCode);

VBScript

Dim strCode

' Generate code
...

Recorder.AddTextToScript strCode

The Recorder.AddSyntaxToScript method allows recording syntax objects directly, without the need to convert them to script code text first:

JScript

var oSyntax;

// Create and configure a syntax object
...

Recorder.AddSyntaxToScript(oSyntax);

VBScript

Dim oSyntax

' Create and configure a syntax object
...

Recorder.AddSyntaxToScript oSyntax

Design-time actions can use the CodeEditor.Text property to insert the generated code right into the script that is in the Code Editor. (See Working With the Code Editor.) Or, if the Code Editor is not active, the action can copy the generated code to the clipboard by assigning it to the Sys.Clipboard property, so that the user can then insert it into the desired script themselves.

JScript

var strCode;

// Generate code
...

// If there is an active Code Editor instance, ...
if (CodeEditor.IsEditorActive)
  // ... insert the code to the current insertion point
  CodeEditor.Text = aqString.Insert(CodeEditor.Text, strCode, CodeEditor.CursorPos);
else
  // Otherwise copy the code to the clipboard
  Sys.Clipboard = strCode;

VBScript

Dim strCode

' Generate code
...

' If there is an active Code Editor instance, ...
If CodeEditor.IsEditorActive Then
  ' ... insert the code to the current insertion point
  CodeEditor.Text = aqString.Insert(CodeEditor.Text, strCode, CodeEditor.CursorPos)
Else
  ' Otherwise copy the code to the clipboard
  Sys.Clipboard = strCode
End If

See Also

Generating Script Code
AddSyntaxToScript Method
AddTextToScript Method
Text Property
Clipboard Property

Highlight search results