ScriptProc Property

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

The object-driven testing (ODT) functionality is deprecated. Do not use it to create new tests. It will be removed from the product in one of the future releases. As an alternative, you can create custom classes in your scripts. For more information, see Alternatives to the ODT functionality.

Description

The Method.ScriptProc property specifies the scripting routine that is used as an object method. The routine must be specified in the unit_name.routine_name format. Both unit_name and routine_name are required. The unit_name specifies the unit where the routine is located. If this unit differs from the class (object) unit, you should specify it in the USEUNIT (uses) clauses of the class unit (see Calling Routines and Variables Declared in Another Unit).

Declaration

MethodObj.ScriptProc

Read-Write Property String
MethodObj An expression, variable or parameter that specifies a reference to a Method object

Applies To

The property is applied to the following object:

Property Value

A string that specifies the scripting routine for the method.

Remarks

To refer to the object instance that the given method belongs to in the routine code, use the keyword Self in DelphiScript or This in VBScript, JScript, C++Script or C#Script (note the first capital):

JavaScript, JScript

function Cls_Method ()
{
  ...
  This.Owner.Owner.Execute();
  ...
}

VBScript

Sub Cls_Method
  ...
  Call This.Owner.Owner.Execute
  ...
End Sub

DelphiScript

procedure Cls_Method;
begin
  ...
  Self.Owner.Owner.Execute;
  ...
end;

C++Script, C#Script

function Cls_Method ()
{
  ...
  This["Owner"]["Owner"]["Execute"]();
  ...
}

Example

The following example obtains the Method object and posts the method’s name and the name of the method’s script routine to the test log.

JavaScript, JScript

function MethodSample()
{
  var NewClass, TestGroup, NewObj, MethodObj;
  // Deletes all the existing classes and variables
  ODT.Data.Clear();
  ODT.Classes.Clear();

  // Declares a new class
  NewClass = ODT.Classes.Declare("NewClass");
  // Declares a new class method
  NewClass.AddMethod("NewClassMethod", "Unit1.Test1");

  // Adds a new group
  TestGroup = ODT.Data.AddGroup("TestGroup");
  // Creates a new variable that represents the object of the NewClass type
  NewObj = TestGroup.AddVarOfClassType("MyVar", "NewClass");
  // Obtains the object’s method by its index
  MethodObj = NewObj.Methods(0);

  // Posts the method’s name
  // And the name of the script routine the method will execute to the test log
  Log.Message("The " + MethodObj.Name + " method executes the " + MethodObj.ScriptProc + " script routine");

}

VBScript

Sub MethodSample

  ' Deletes all the existing classes and variables
  ODT.Data.Clear
  ODT.Classes.Clear

  ' Declares a new class
  Set NewClass = ODT.Classes.Declare("NewClass")
  ' Declares a new class method
  Call NewClass.AddMethod("NewClassMethod", "Unit1.Test1")

  ' Adds a new group
  Set TestGroup = ODT.Data.AddGroup("TestGroup")
  ' Creates a new variable that represents the object of the NewClass type
  Set NewObj = TestGroup.AddVarOfClassType("MyVar", "NewClass")
  ' Obtains the object’s method by its index
  Set MethodObj = NewObj.Methods(0)

  ' Posts the method’s name
  ' And the name of the script routine the method will execute to the test log
  Log.Message "The " & MethodObj.Name & " method executes the " & MethodObj.ScriptProc & " script routine"

End Sub

DelphiScript

procedure MethodSample();
var NewClass, TestGroup, NewObj, MethodObj;
begin
  // Deletes all the existing classes and variables
  ODT.Data.Clear;
  ODT.Classes.Clear;

  // Declares a new class
  NewClass := ODT.Classes.Declare('NewClass');
  // Declares a new class method
  NewClass.AddMethod('NewClassMethod', 'Unit1.Test1');

  // Adds a new group
  TestGroup := ODT.Data.AddGroup('TestGroup');
  // Creates a new variable that represents the object of the NewClass type
  NewObj := TestGroup.AddVarOfClassType('MyVar', 'NewClass');
  // Obtains the object’s method by its index
  MethodObj := NewObj.Methods[0];

  // Posts the method’s name
  // And the name of the script routine the method will execute to the test log
  Log.Message('The ' + MethodObj.Name + ' method executes the ' + MethodObj.ScriptProc + ' script routine');

end;

C++Script, C#Script

function MethodSample()
{
  // Deletes all the existing classes and variables
  var NewClass, TestGroup, NewObj, MethodObj;
  ODT["Data"]["Clear"]();
  ODT["Classes"]["Clear"]();

  // Declares a new class
  NewClass = ODT["Classes"]["Declare"]("NewClass");
  // Declares a new class method
  NewClass["AddMethod"]("NewClassMethod", "Unit1.Test1");

  // Adds a new group
  TestGroup = ODT["Data"]["AddGroup"]("TestGroup");
  // Creates a new variable that represents the object of the NewClass type
  NewObj = TestGroup["AddVarOfClassType"]("MyVar", "NewClass");
  // Obtains the object’s method by its index
  MethodObj = NewObj["Methods"](0);

  // Posts the method’s name
  // And the name of the script routine the method will execute to the test log
  Log["Message"]("The " + MethodObj["Name"] + " method executes the " + MethodObj["ScriptProc"] + " script routine");

}

See Also

ScriptProc Property
Name Property
Object Object

Highlight search results