Syntax.GenerateSource Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

The Syntax.GenerateScript method can be used in script extensions to generate script code that corresponds to a single syntax element or a collection of syntax elements. The code is generated in the same language -- JavaScript, JScript, Python, VBScript, DelphiScript, C#Script or C++Script -- that is used in the user’s current TestComplete project.

After generating the script code, you can use it as your needs dictate. For example, if you create a recording action, you can use the Recorder.AddTextToScript method to insert the generated code into the script being recorded. Or, if you create a design-time action, you can copy the code to the clipboard using the Sys.Clipboard property.

Declaration

Syntax.GenerateSource(Syntax)

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

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Syntax

Result Value

A string that holds the generated script code.

Remarks

Note: you can also directly “pass” syntax elements to the TestComplete recording engine using the Recorder.AddSyntaxToScript method.

Example

The sample code below generates the Log.Message call code and displays this code in a message box:

JScript

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

  // Generate and display the script code
  var strCode = Syntax.GenerateSource(oCall);
  aqDlg.ShowMessage(strCode);
}

VBScript

Sub ShowLogMessageCall
  Dim oCall, strCode

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

  ' Generate and display the script code
  strCode = Syntax.GenerateSource(oCall)
  aqDlg.ShowMessage strCode
End Sub

See Also

Script Extensions
AddTextToScript Method
AddSyntaxToScript Method
Clipboard Property

Highlight search results