Count Property

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

Description

The Count property returns the number of hosts in the host collection represented by the Hosts object.

Declaration

HostsObj.Count

Read-Only Property Integer
HostsObj An expression, variable or parameter that specifies a reference to a Hosts object

Applies To

The property is applied to the following object:

Property Value

An integer value that means the number of hosts in the host collection.

Example

The code below obtains the number of items in the host collection, then iterates through all the items, gets their names and posts these names to the test log.

JavaScript, JScript

function HostsCount()
{
  // Obtains the number of hosts in the collection
  var Num = NetworkSuite.Hosts.Count;
  
  // Iterates through the host collection
  for (var i = 0; i <Num; i++)
  {
    // Obtains the current host
    var Item = NetworkSuite.Hosts.Items(i);
    // Gets the name of the current host
    var Name = Item.Name;
    // Posts the name of the current host to the test log
    Log.Message(i+1 + " host: " + Name);
  }
  
}

Python

def HostsCount():
  # Obtains the number of hosts in the collection
  Num = NetworkSuite.Hosts.Count
  # Iterates through the host collection
  for i in range (0, Num):
    # Obtains the current host
    Item = NetworkSuite.Hosts.Items[i]
    # Gets the name of the current host
    Name = Item.Name
    # Posts the name of the current host to the test log
    Log.Message(str(i + 1) + " host: " + Name)

VBScript

Sub HostsCount()

  ' Obtains the number of hosts in the collection
  Num = NetworkSuite.Hosts.Count
  
  ' Iterates through the host collection
  For i = 0 to (Num-1)
    ' Obtains the current host
    Set Item = NetworkSuite.Hosts.Items(i)
    ' Gets the name of the current host
    Name = Item.Name
    ' Posts the name of the current host to the test log
    Log.Message(i+1 & " host: " & Name)
  Next
  
End Sub

DelphiScript

function HostsCount;
var Num, i, Item, Name;
begin

  // Obtains the number of hosts in the collection
  Num := NetworkSuite.Hosts.Count;
  
  // Iterates through the host collection
  for i := 0 to (Num - 1) do
  begin
    // Obtains the current host
    Item := NetworkSuite.Hosts.Items[i];
    // Gets the name of the current host
    Name := Item.Name;
    // Posts the name of the current host to the test log
    Log.Message(i+1 + ' host: ' + Name);
  end;
  
end;

C++Script, C#Script

function HostsCount()
{
  // Obtains the number of hosts in the collection
  var Num = NetworkSuite["Hosts"]["Count"];
  
  // Iterates through the host collection
  for (var i = 0; i <Num; i++)
  {
    // Obtains the current host
    var Item = NetworkSuite["Hosts"]["Items"](i);
    // Gets the name of the current host
    var Name = Item["Name"];
    // Posts the name of the current host to the test log
    Log["Message"](i+1 + " host: " + Name);
  }
  
}

See Also

Distributed Testing
Items Property
ItemByName Property
AddNew Method

Highlight search results