ItemCount Property

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

A test item can have a number of child items. The TestItems.ItemCount property returns the total number of direct child items for the current test item (that is, child items of the given test item, but not children of its child items). To address the child item by its index, use the TestItem.TestItem property.

Declaration

Project TestItemObj.ItemCount

Read-Only Property Integer
Project TestItemObj An expression, variable or parameter that specifies a reference to a Project TestItem object

Applies To

The property is applied to the following object:

Property Value

The number of child items for the current test item.

Example

The following example iterates through a project’s test items and posts their properties to the test log:

JavaScript

function Test()
{
  // Iterates through test items
  for (let i = 0; i < Project.TestItems.ItemCount; i++)
    LogTestItemInfo(Project.TestItems.TestItem(i));
}

function LogTestItemInfo(ATestItem)
{
  var TestItemInfo;
  // Obtains the test item name
  TestItemInfo = "Name: " + ATestItem.Name + "\r\n";

  // Obtains the test item description
  TestItemInfo = TestItemInfo + "Description: " + ATestItem.Description + "\r\n";

  // Obtains the name of the test run by the test item
  TestItemInfo = TestItemInfo + "Test: ";
  if (!strictEqual(ATestItem.ElementToBeRun, null))
    TestItemInfo = TestItemInfo + ATestItem.ElementToBeRun.Caption + "\r\n"
  else
    TestItemInfo = TestItemInfo + "not specified" + "\r\n";

  // Obtains the name of the parent item of the current test item
  TestItemInfo = TestItemInfo + "Parent: ";
  if (!strictEqual(ATestItem.Parent, null))
    TestItemInfo = TestItemInfo + ATestItem.Parent.Name + "\r\n"
  else
    TestItemInfo = TestItemInfo + "none" + "\r\n";

  // Determines whether the current test item is enabled
  TestItemInfo = TestItemInfo + "Enabled: " + ATestItem.Enabled + "\r\n";

  // Obtains the test item’s StopOnError property value
  TestItemInfo = TestItemInfo + "On error: ";
  switch (ATestItem.StopOnError)
    {     case 0:
      TestItemInfo = TestItemInfo + "Continue running" + "\r\n";
      break;
    case 1:
      TestItemInfo = TestItemInfo + "Stop project" + "\r\n";
      break;
    case 2:
      TestItemInfo = TestItemInfo + "Stop current item" + "\r\n";
      break;
    case 3:
      TestItemInfo = TestItemInfo + "Use project's On error property" + "\r\n";
      break;
    }

  // Obtains the test item’s StopOnException property value
  TestItemInfo = TestItemInfo + "On exception: ";
  switch (ATestItem.StopOnException)
    {
    case 0:
      TestItemInfo = TestItemInfo + "Continue running" + "\r\n";
      break;
    case 1:
      TestItemInfo = TestItemInfo + "Stop project" + "\r\n";
      break;
    case 2:
      TestItemInfo = TestItemInfo + "Stop current item" + "\r\n";
      break;
    }

  // Obtains the amount of time the test item is executed
  TestItemInfo = TestItemInfo + "Count: " + ATestItem.Count + "\r\n";

  // Obtains the test item’s timeout
  TestItemInfo = TestItemInfo + "Timeout: " + ATestItem.Timeout + "\r\n";

  // Checks if the test item is currently running
  TestItemInfo = TestItemInfo + "Is currently running: ";
  if (ATestItem.Iteration > 0)
    TestItemInfo = TestItemInfo + "yes"
  else
    TestItemInfo = TestItemInfo + "no";

  // Posts test item information to the test log
  Log.AppendFolder(ATestItem.Name, TestItemInfo);

  // Iterates through the child items of the current test item
  for (let i = 0; i < ATestItem.ItemCount; i++)

    // Posts information on the current test item’s child items to the test log
    LogTestItemInfo(ATestItem.TestItem(i));
  Log.PopLogFolder();
}

JScript

function Test()
{
  var i;
  // Iterates through test items
  for (i = 0; i < Project.TestItems.ItemCount; i++)
    LogTestItemInfo(Project.TestItems.TestItem(i));
}

function LogTestItemInfo(ATestItem)
{
  var TestItemInfo, i;
  // Obtains the test item name
  TestItemInfo = "Name: " + ATestItem.Name + "\r\n";

  // Obtains the test item description
  TestItemInfo = TestItemInfo + "Description: " + ATestItem.Description + "\r\n";

  // Obtains the name of the test run by the test item
  TestItemInfo = TestItemInfo + "Test: ";
  if (ATestItem.ElementToBeRun != null)
    TestItemInfo = TestItemInfo + ATestItem.ElementToBeRun.Caption + "\r\n"
  else
    TestItemInfo = TestItemInfo + "not specified" + "\r\n";

  // Obtains the name of the parent item of the current test item
  TestItemInfo = TestItemInfo + "Parent: ";
  if (ATestItem.Parent != null)
    TestItemInfo = TestItemInfo + ATestItem.Parent.Name + "\r\n"
  else
    TestItemInfo = TestItemInfo + "none" + "\r\n";

  // Determines whether the current test item is enabled
  TestItemInfo = TestItemInfo + "Enabled: " + ATestItem.Enabled + "\r\n";

  // Obtains the test item’s StopOnError property value
  TestItemInfo = TestItemInfo + "On error: ";
  switch (ATestItem.StopOnError)
    {     case 0:
      TestItemInfo = TestItemInfo + "Continue running" + "\r\n";
      break;
    case 1:
      TestItemInfo = TestItemInfo + "Stop project" + "\r\n";
      break;
    case 2:
      TestItemInfo = TestItemInfo + "Stop current item" + "\r\n";
      break;
    case 3:
      TestItemInfo = TestItemInfo + "Use project's On error property" + "\r\n";
      break;
    }

  // Obtains the test item’s StopOnException property value
  TestItemInfo = TestItemInfo + "On exception: ";
  switch (ATestItem.StopOnException)
    {
    case 0:
      TestItemInfo = TestItemInfo + "Continue running" + "\r\n";
      break;
    case 1:
      TestItemInfo = TestItemInfo + "Stop project" + "\r\n";
      break;
    case 2:
      TestItemInfo = TestItemInfo + "Stop current item" + "\r\n";
      break;
    }

  // Obtains the amount of time the test item is executed
  TestItemInfo = TestItemInfo + "Count: " + ATestItem.Count + "\r\n";

  // Obtains the test item’s timeout
  TestItemInfo = TestItemInfo + "Timeout: " + ATestItem.Timeout + "\r\n";

  // Checks if the test item is currently running
  TestItemInfo = TestItemInfo + "Is currently running: ";
  if (ATestItem.Iteration > 0)
    TestItemInfo = TestItemInfo + "yes"
  else
    TestItemInfo = TestItemInfo + "no";

  // Posts test item information to the test log
  Log.AppendFolder(ATestItem.Name, TestItemInfo);

  // Iterates through the child items of the current test item
  for (i = 0; i < ATestItem.ItemCount; i++)

    // Posts information on the current test item’s child items to the test log
    LogTestItemInfo(ATestItem.TestItem(i));
  Log.PopLogFolder();
}

Python

def Test():
  # Iterates through test items
  for i in range(0, Project.TestItems.ItemCount):
    LogTestItemInfo(Project.TestItems.TestItem[i])

def LogTestItemInfo(ATestItem):
  # Obtains the test item name 
  TestItemInfo = "Name: " + str(ATestItem.Name) + "\r\n"
  # Obtains the test item description 
  TestItemInfo = TestItemInfo + "Description: " + str(ATestItem.Description) + "\r\n"
  # Obtains the name of the test run by the test item 
  TestItemInfo = TestItemInfo + "Test: "
  if ATestItem.ElementToBeRun != None:
    TestItemInfo = TestItemInfo + ATestItem.ElementToBeRun.Caption + "\r\n"
  else:
    TestItemInfo = TestItemInfo + "not specified" + "\r\n"
  # Obtains the name of the parent item of the current test item 
  TestItemInfo = TestItemInfo + "Parent: "
  if ATestItem.Parent != None:
    TestItemInfo = TestItemInfo + str(ATestItem.Parent.Name) + "\r\n"
  else:
    TestItemInfo = TestItemInfo + "none" + "\r\n"
  # Determines whether the current test item is enabled 
  TestItemInfo = TestItemInfo + "Enabled: " + str(ATestItem.Enabled) + "\r\n"
  # Obtains the test item's StopOnError property value 
  TestItemInfo = TestItemInfo + "On error: "
  if ATestItem.StopOnError == 0:
    TestItemInfo = TestItemInfo + "Continue running" + "\r\n"
  elif ATestItem.StopOnError == 1:
    TestItemInfo = TestItemInfo + "Stop project" + "\r\n"
  elif ATestItem.StopOnError == 2:
    TestItemInfo = TestItemInfo + "Stop test item" + "\r\n"
  elif ATestItem.StopOnError == 3:
    TestItemInfo = TestItemInfo + "Use project's On error property" + "\r\n"
  # Obtains the test item's StopOnException property value 
  TestItemInfo = TestItemInfo + "On exception: "
  if ATestItem.StopOnException == 0:
    TestItemInfo = TestItemInfo + "Continue running" + "\r\n"
  elif ATestItem.StopOnException == 1:
    TestItemInfo = TestItemInfo + "Stop project" + "\r\n"
  elif ATestItem.StopOnException == 2:
    TestItemInfo = TestItemInfo + "Stop test item" + "\r\n"
  # Obtains the amount of time the test item is executed 
  TestItemInfo = TestItemInfo + "Count: " + str(ATestItem.Count) + "\r\n"
  # Obtains the test item's timeout
  TestItemInfo = TestItemInfo + "Timeout: " + str(ATestItem.Timeout) + "\r\n"
  # Checks if the test item is currently running 
  TestItemInfo = TestItemInfo + "Is currently running: "
  if ATestItem.Iteration > 0:
    TestItemInfo = TestItemInfo + "yes"
  else:
    TestItemInfo = TestItemInfo + "no"
  # Posts test item information to the test log
  Log.AppendFolder(ATestItem.Name, TestItemInfo)
  # Iterates through the child items of the current test item
  for i in range(0, ATestItem.ItemCount):
    # Posts information on the current test item's child items to the test log 
    LogTestItemInfo(ATestItem.TestItem[i])
  Log.PopLogFolder()

VBScript

Sub Test
  Dim i
  ' Iterates through test items
  For i = 0 To Project.TestItems.ItemCount - 1
    LogTestItemInfo(Project.TestItems.TestItem(i))
  Next
End Sub

Sub LogTestItemInfo(ATestItem)
  Dim TestItemInfo, i
  ' Obtains the test item name
  TestItemInfo = "Name: " & ATestItem.Name & vbCrLf

  ' Obtains the test item description
  TestItemInfo = TestItemInfo & "Description: " & ATestItem.Description & vbCrLf

  ' Obtains the name of the test run by the test item
  TestItemInfo = TestItemInfo & "Test: "
  If Not ATestItem.ElementToBeRun Is Nothing Then
    TestItemInfo = TestItemInfo & ATestItem.ElementToBeRun.Caption & vbCrLf
  Else
    TestItemInfo = TestItemInfo & "not specified" & vbCrLf
  End If

  ' Obtains the name of the parent item of the current test item
  TestItemInfo = TestItemInfo & "Parent: "
  If Not ATestItem.Parent Is Nothing Then
    TestItemInfo = TestItemInfo & ATestItem.Parent.Name & vbCrLf
  Else
    TestItemInfo = TestItemInfo & "none" & vbCrLf
  End If

  ' Determines whether the current test item is enabled
  TestItemInfo = TestItemInfo & "Enabled: " & ATestItem.Enabled & vbCrLf

  ' Obtains the test item’s StopOnError property value
  TestItemInfo = TestItemInfo & "On error: "
  Select Case ATestItem.StopOnError
    Case 0 TestItemInfo = TestItemInfo & "Continue running" & vbCrLf
    Case 1 TestItemInfo = TestItemInfo & "Stop project" & vbCrLf
    Case 2 TestItemInfo = TestItemInfo & "Stop current item" & vbCrLf
    Case 3 TestItemInfo = TestItemInfo & "Use project's On error property" & vbCrLf
  End Select

  ' Obtains the test item’s StopOnException property value
  TestItemInfo = TestItemInfo & "On exception: "
  Select Case ATestItem.StopOnException
    Case 0 TestItemInfo = TestItemInfo & "Continue running" & vbCrLf
    Case 1 TestItemInfo = TestItemInfo & "Stop project" & vbCrLf
    Case 2 TestItemInfo = TestItemInfo & "Stop current item" & vbCrLf
  End Select

  ' Obtains the amount of time the test item is executed
  TestItemInfo = TestItemInfo & "Count: " & ATestItem.Count & vbCrLf

  ' Obtains the test item’s timeout
  TestItemInfo = TestItemInfo & "Timeout: " & ATestItem.Timeout & vbCrLf

  ' Checks if the test item is currently running
  TestItemInfo = TestItemInfo & "Is currently running: "
  If ATestItem.Iteration > 0 Then
    TestItemInfo = TestItemInfo & "yes"
  Else
    TestItemInfo = TestItemInfo & "no"
  End If

  ' Posts test item information to the test log
  Call Log.AppendFolder(ATestItem.Name, TestItemInfo)

  ' Iterates through the child items of the current test item
  For i = 0 To ATestItem.ItemCount-1

    ' Posts information on the current test item’s child items to the test log
    LogTestItemInfo(ATestItem.TestItem(i))
  Next
  Log.PopLogFolder
End Sub

DelphiScript

procedure LogTestItemInfo(ATestItem);
var TestItemInfo, i;
begin
  // Obtains the test item name
  TestItemInfo := 'Name: ' + ATestItem.Name + #13#10;

  // Obtains the test item description
  TestItemInfo := TestItemInfo + 'Description: ' + ATestItem.Description + #13#10;

  // Obtains the name of the test run by the test item
  TestItemInfo := TestItemInfo + 'Test: ';
  if ATestItem.ElementToBeRun <> nil then
    TestItemInfo := TestItemInfo + ATestItem.ElementToBeRun.Caption + #13#10
  else
    TestItemInfo := TestItemInfo + 'not specified' + #13#10;

  // Obtains the name of the parent item of the current test item
  TestItemInfo := TestItemInfo + 'Parent: ';
  if ATestItem.Parent <> nil then
    TestItemInfo := TestItemInfo + ATestItem.Parent.Name + #13#10
  else
    TestItemInfo := TestItemInfo + 'none' + #13#10;

  // Determines whether the current test item is enabled
  TestItemInfo := TestItemInfo + 'Enabled: ' + aqConvert.VarToStr(ATestItem.Enabled) + #13#10;

  // Obtains the test item’s StopOnError property value
  TestItemInfo := TestItemInfo + 'On error: ';
  case ATestItem.StopOnError of
    0: TestItemInfo := TestItemInfo + 'Continue running' + #13#10;
    1: TestItemInfo := TestItemInfo + 'Stop project' + #13#10;
    2: TestItemInfo := TestItemInfo + 'Stop current item' + #13#10;
    3: TestItemInfo := TestItemInfo + 'Use project''s On error property' + #13#10;
    end;

  // Obtains the test item’s StopOnException property value
  TestItemInfo := TestItemInfo + 'Stop on exception: ';
  case ATestItem.StopOnException of
    0: TestItemInfo := TestItemInfo + 'Continue running' + #13#10;
    1: TestItemInfo := TestItemInfo + 'Stop project' + #13#10;
    2: TestItemInfo := TestItemInfo + 'Stop current item' + #13#10;
    end;

  // Obtains the amount of time the test item is executed
  TestItemInfo := TestItemInfo + 'Count: ' + aqConvert.VarToStr(ATestItem.Count) + #13#10;

  // Obtains the test item’s timeout
  TestItemInfo := TestItemInfo + 'Timeout: ' + aqConvert.VarToStr(ATestItem.Timeout) + #13#10;

  // Checks if the test item is currently running
  TestItemInfo := TestItemInfo + 'Is currently running: ';
  if ATestItem.Iteration > 0 then
    TestItemInfo := TestItemInfo + 'yes'
  else
    TestItemInfo := TestItemInfo + 'no';

  // Posts test item information to the test log
  Log.AppendFolder(ATestItem.Name, TestItemInfo);

  // Iterates through the child items of the current test item
  for i := 0 to ATestItem.ItemCount - 1 do

    // Posts information on the current test item’s child items to the test log
    LogTestItemInfo(ATestItem.TestItem(i));
  Log.PopLogFolder;
end;

procedure Test();
var i;
begin
  // Iterates through test items
  for i := 0 to Project.TestItems.ItemCount - 1 do
    LogTestItemInfo(Project.TestItems.TestItem(i));
end;

C++Script, C#Script

function Test()
{
  var i;
  // Iterates through test items
  for (i = 0; i < Project["TestItems"]["ItemCount"]; i++)
    LogTestItemInfo(Project["TestItems"]["TestItem"](i));
}

function LogTestItemInfo(ATestItem)
{
  var TestItemInfo, i;
  // Obtains the test item name
  TestItemInfo = "Name: " + ATestItem["Name"] + "\r\n";

  // Obtains the test item description
  TestItemInfo = TestItemInfo + "Description: " + ATestItem["Description"] + "\r\n";

  // Obtains the name of the test run by the test item
  TestItemInfo = TestItemInfo + "Test: ";
  if (ATestItem["ElementToBeRun"] != null)
    TestItemInfo = TestItemInfo + ATestItem["ElementToBeRun"]["Caption"] + "\r\n"
  else
    TestItemInfo = TestItemInfo + "not specified" + "\r\n";

  // Obtains the name of the parent item of the current test item
  TestItemInfo = TestItemInfo + "Parent: ";
  if (ATestItem["Parent"] != null)
    TestItemInfo = TestItemInfo + ATestItem["Parent"]["Name"] + "\r\n"
  else
    TestItemInfo = TestItemInfo + "none" + "\r\n";

  // Determines whether the current test item is enabled
  TestItemInfo = TestItemInfo + "Enabled: " + ATestItem["Enabled"] + "\r\n";

  // Obtains the test item’s StopOnError property value
  TestItemInfo = TestItemInfo + "On error: ";
  switch (ATestItem["StopOnError"])
    {     case 0:
      TestItemInfo = TestItemInfo + "Continue running" + "\r\n";
      break;
    case 1:
      TestItemInfo = TestItemInfo + "Stop project" + "\r\n";
      break;
    case 2:
      TestItemInfo = TestItemInfo + "Stop current item" + "\r\n";
      break;
    case 3:
      TestItemInfo = TestItemInfo + "Use project's On error property" + "\r\n";
      break;
    }

  // Obtains the test item’s StopOnException property value
  TestItemInfo = TestItemInfo + "On exception: ";
  switch (ATestItem["StopOnException"])
    {
    case 0:
      TestItemInfo = TestItemInfo + "Continue running" + "\r\n";
      break;
    case 1:
      TestItemInfo = TestItemInfo + "Stop project" + "\r\n";
      break;
    case 2:
      TestItemInfo = TestItemInfo + "Stop current item" + "\r\n";
      break;
    }

  // Obtains the amount of time the test item is executed
  TestItemInfo = TestItemInfo + "Count: " + ATestItem["Count"] + "\r\n";

  // Obtains the test item’s timeout
  TestItemInfo = TestItemInfo + "Timeout: " + ATestItem["Timeout"] + "\r\n";

  // Checks if the test item is currently running
  TestItemInfo = TestItemInfo + "Is currently running: ";
  if (ATestItem["Iteration"] > 0)
    TestItemInfo = TestItemInfo + "yes"
  else
    TestItemInfo = TestItemInfo + "no";

  // Posts test item information to the test log
  Log.AppendFolder(ATestItem["Name"], TestItemInfo);

  // Iterates through the child items of the current test item
  for (i = 0; i < ATestItem["ItemCount"]; i++)

    // Posts information on the current test item’s child items to the test log
    LogTestItemInfo(ATestItem["TestItem"](i));
  Log["PopLogFolder"]();
}

See Also

Current Property (Specific to Project Object)
Parent Property
TestItem Property

Highlight search results