Method Object

Applies to TestComplete 15.70, last modified on December 17, 2024

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 objects provide a scripting interface to methods of objects that were created via the ODT project item.

The Method object provides the same properties as the MethodDeclaration object plus additional properties that let you specify whether the method is the “Init” method and whether it is processed by ODT Run methods. To obtain the Method object in scripts, use the Methods property or AddMethod method of the Object object.

Members

Example

The following example demonstrates how to obtain the Method object. It declares a new class, creates a variable that contains an object of the declared class type and obtains the object's method.

JavaScript, JScript

function MethodSample()
{
  var NewClass, TestGroup, NewObj, MethodObj;
  ODT.Data.Clear();
  ODT.Classes.Clear();

  // Declares a new class
  NewClass = ODT.Classes.Declare("NewClass");
  // Declares a new method in the class
  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);

  …

}

VBScript

Sub MethodSample

  ODT.Data.Clear
  ODT.Classes.Clear

  ' Declares a new class
  Set NewClass = ODT.Classes.Declare("NewClass")
  ' Declares a new method in the class
  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)

  …

End Sub

DelphiScript

procedure MethodSample();
var NewClass, TestGroup, NewObj, MethodObj;
begin
  ODT.Data.Clear;
  ODT.Classes.Clear;

  // Declares a new class
  NewClass := ODT.Classes.Declare('NewClass');
  // Declares a new method in the class
  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];

  …

end;

C++Script, C#Script

function MethodSample()
{
  var NewClass, TestGroup, NewObj, MethodObj;
  ODT["Data"]["Clear"]();
  ODT["Classes"]["Clear"]();

  // Declares a new class
  NewClass = ODT["Classes"]["Declare"]("NewClass");
  // Declares a new method in the class
  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);

  …

}

See Also

MethodDeclaration Object
Object Object
AddMethod Method
Methods Property
Property Object

Highlight search results