Object Object

Applies to TestComplete 15.45, last modified on December 01, 2022

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 Object objects provide a scripting interface to custom objects created via the ODT project item. Once you obtain this interface for an object, you can add properties and methods to it, modify property values and perform other operations from scripts.

Members

Example

The following example declares a new class, adds a property and a method to it and creates an object that contains an instance of the declared class. After that, it adds another property and method to the object and calls the Run method that processes the object’s properties and executes the object’s methods.

JavaScript, JScript

function ObjectSample()
{
  var NewClass, MyObject;
  // Declares a new class
  NewClass = ODT.Classes.Declare("NewClass");
  NewClass.AddProperty("ClassProperty", "Value");
  NewClass.AddMethod("ClassMethod", "Unit1.Test1");

  // Creates an object based on the declared class
  MyObject = ODT.Classes.New("NewClass");
  MyObject.AddProperty("ObjectProperty", 10);
  MyObject.AddMethod("ObjectMethod", "Unit1.Test2");
  // Enables all the object’s methods
  for (var i = 0; i < MyObject.MethodCount; i++)
    MyObject.Methods(i).Enabled = true;

  // Processes the object’s properties and calls the object’s methods
  MyObject.Run();

}

VBScript

Sub ObjectSample

  ' Declares a new class
  Set NewClass = ODT.Classes.Declare("NewClass")
  Call NewClass.AddProperty("ClassProperty", "Value")
  Call NewClass.AddMethod("ClassMethod", "Unit1.Test1")

  ' Creates an object based on the declared class
  Set MyObject = ODT.Classes.New("NewClass")
  Call MyObject.AddProperty("ObjectProperty", 10)
  Call MyObject.AddMethod("ObjectMethod", "Unit1.Test2")
  ' Enables all the object’s methods
  For i = 0 To MyObject.MethodCount - 1
    MyObject.Methods(i).Enabled = True
  Next
  ' Processes the object’s properties and calls the object’s methods
  MyObject.Run

End Sub

DelphiScript

procedure ObjectSample();
var NewClass, MyObject, i;
begin
  // Declares a new class
  NewClass := ODT.Classes.Declare('NewClass');
  NewClass.AddProperty('ClassProperty', 'Value');
  NewClass.AddMethod('ClassMethod', 'Unit1.Test1');

  // Creates an object based on the declared class
  MyObject := ODT.Classes.New('NewClass');
  MyObject.AddProperty('ObjectProperty', 10);
  MyObject.AddMethod('ObjectMethod', 'Unit1.Test2');
  // Enables all the object’s methods
  for i := 0 to MyObject.MethodCount - 1 do
    MyObject.Methods[i].Enabled := true;

  // Processes the object’s properties and calls the object’s methods
  MyObject.Run;

end;

C++Script, C#Script

function ObjectSample()
{
  var NewClass, MyObject;
  // Declares a new class
  NewClass = ODT["Classes"]["Declare"]("NewClass");
  NewClass["AddProperty"]("ClassProperty", "Value");
  NewClass["AddMethod"]("ClassMethod", "Unit1.Test1");

  // Creates an object based on the declared class
  MyObject = ODT["Classes"]["New"]("NewClass");
  MyObject["AddProperty"]("ObjectProperty", 10);
  MyObject["AddMethod"]("ObjectMethod", "Unit1.Test2");
  // Enables all the object’s methods
  for (var i = 0; i < MyObject["MethodCount"]; i++)
    MyObject["Methods"](i)["Enabled"] = true;

  // Processes the object’s properties and calls the object’s methods
  MyObject["Run"]();

}

See Also

Class Object
Group Object
Data Object
ODT Object

Highlight search results