Recorder.AddSyntaxToScript Method

Applies to TestComplete 14.40, last modified on April 22, 2021

Description

The AddSyntaxToScript method inserts the script code corresponding to the specified syntax object into the script being recorded.

To insert comments into the recorded code, use the Recorder.AddTextToScript method.

Declaration

Recorder.AddSyntaxToScript(Syntax)

Syntax [in]    Required    An AssignSyntax, CollectionSyntax, ConditionSyntax, IfSyntax, InvokeSyntax or VarDefSyntax object    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Syntax

One of the following syntax objects that correspond to various code statements:

Result Value

None.

Remarks

This method can be used only in recording-time actions. It has no effect at design-time.

Note that instead of using the Recorder.AddSyntaxToScript method, you can generate the script code based on the syntax object using the Syntax.GenerateSource method, and then add the generated code to the script using the Recorder.AddTextToScript method. This two-step procedure can be useful, for example, if you want to give the users the possibility to preview the code before adding it to the script.

Example

The following example demonstrates how you can insert the Log.Message method call into the script being recorded:

JScript

function RecordLogMessageCall()
{
  // Create the Log.Message method call statement
  var oCall = Syntax.CreateInvoke();
  oCall.ClassValue = "Log";
  oCall.InvokeName = "Message";
  oCall.AddParameter("Hello, world!");
  oCall.IsProperty = false;

  // Add the created statement to the script
  Recorder.AddSyntaxToScript(oCall);
}

VBScript

Sub RecordLogMessageCall
  Dim oCall

  ' Create the Log.Message method call statement
  Set oCall = Syntax.CreateInvoke
  oCall.ClassValue = "Log"
  oCall.InvokeName = "Message"
  oCall.AddParameter "Hello, world!"
  oCall.IsProperty = False

  ' Add the created statement to the script
  Recorder.AddSyntaxToScript oCall
End Sub

See Also

Script Extensions
AddTextToScript Method
Syntax Object
AssignSyntax Object
CollectionSyntax Object
ConditionSyntax Object
IfSyntax Object
InvokeSyntax Object
VarDefSyntax Object

Highlight search results