Enumerator Object

Applies to TestComplete 15.63, last modified on April 10, 2024

Description

The Enumerator object maintains a collection of child objects from a test object, for example, the collection of windows belonging to a process, and is available through the _NewEnum property of test objects. Enumerator provides a way to enumerate the child object collection without the need to know the specific types of the child objects. It also enables using intrinsic functions and statements of the scripting languages supported by TestComplete to enumerate this collection. For instance, you can use the for...of statement in JavaScript code, the Enumerator object in JavaScript, JScript, Python, C#Script or C++Script code, the For Each statement in VBScript code or the Utils.Enumerator method available for any scripting language.

You can use the Enumerator properties while exploring an object’s child objects collection in the Object Browser or the Object Spy window. However, these properties are not intended to be used directly in tests. In tests, you enumerate the child objects collection using the Child method and the ChildCount property or using intrinsic functionality of scripting languages (see below).

Members

Example

The following example demonstrates how you can enumerate all running processes on the computer and log their names:

JavaScript

function Test()
{
  for (let p of Sys)
    Log.Message(p.Name);
}

JScript

function Test()
{
  var iterator = new Enumerator(Sys);
  for (; !iterator.atEnd(); iterator.moveNext())
    Log.Message(iterator.item().Name);
}

Python

def Test():
  enum = Enumerator(Sys)

  while not enum.AtEnd:
    Log.Message(enum.Item.Name)
    enum.moveNext()

VBScript

Sub Test
  Dim p

  For Each p In Sys
    Log.Message p.Name
  Next
End Sub

DelphiScript

procedure Test;
var enum;
begin
  enum := Utils.Enumerator(Sys);

  while not enum.AtEnd do
  begin
    Log.Message(enum.Item.Name);
    enum.MoveNext;
  end;
end;

C++Script, C#Script

function Test()
{
  var iterator = new Enumerator(Sys);
  for (; !iterator["atEnd"](); iterator["moveNext"]())
    Log["Message"](iterator["item"]()["Name"]);
}

See Also

_NewEnum Property
Child Method
ChildCount Property

Highlight search results