TestItems Object (Specific to Project Object)

Applies to TestComplete 14.30, last modified on November 21, 2019

Description

The TestItems object provides a scripting interface to the project test items specified on the Test Items page of the Project Editor.

To obtain the collection of a project’s test items in scripts, use the TestItems property of the Project object.

Members

Example

The following example obtains the total number of project test items, iterates through them and posts their names to the test log.

JavaScript, JScript

function Test()
{
  var i, TestItems, Count;
  // Obtains the collection of project test items
  TestItems = Project.TestItems;
  // Defines the total number of test items in the project
  Count = TestItems.ItemCount;
  // Iterates through the project’s test items
  for (i = 0; i < Count; i++)
    ProcessTestItem(TestItems.TestItem(i));
}

function ProcessTestItem(ATestItem)
{
  // Posts the test item name
  Log.AppendFolder(ATestItem.Name);
  // If the test item contains child items, iterates through them
  for (var i = 0; i < ATestItem.ItemCount; i++)
    ProcessTestItem(ATestItem.TestItem(i));
  Log.PopLogFolder();
}

Python

def Test():
  # Obtains the collection of project test items 
  TestItems = Project.TestItems
  # Defines the total number of test items in the project 
  Count = TestItems.ItemCount
  # Iterates through the project's test items 
  for i in range(0, Count):
    ProcessTestItem(TestItems.TestItem[i])

def ProcessTestItem(ATestItem):
  # Posts the test item name
  Log.AppendFolder(ATestItem.Name)
  # If the test item contains child items, iterates through them 
  for i in range(0, ATestItem.ItemCount):
    ProcessTestItem(ATestItem.TestItem[i])
  Log.PopLogFolder()

VBScript

Sub Test
  Dim i, TestItems, Count
  ' Obtains the collection of project test items
  Set TestItems = Project.TestItems
  ' Defines the total number of test items in the project
  Count = TestItems.ItemCount
  ' Iterates through the project’s test items
  For i = 0 To Count-1
    ProcessTestItem(TestItems.TestItem(i))
  Next
End Sub

Sub ProcessTestItem(ATestItem)
  ' Posts the test item name
  Call Log.AppendFolder(ATestItem.Name)
  ' If the test item contains child items, iterates through them
  For i = 0 To ATestItem.ItemCount-1
    ProcessTestItem(ATestItem.TestItem(i))
  Next
  Log.PopLogFolder
End Sub

DelphiScript

procedure ProcessTestItem(ATestItem);
var i;
begin
  // Posts the test item name
  Log.AppendFolder(ATestItem.Name);
  // If the test item contains child items, iterates through them
  for i := 0 to ATestItem.ItemCount - 1 do
    ProcessTestItem(ATestItem.TestItem(i));
  Log.PopLogFolder();
end;

procedure Test();
var i, TestItems, Count;
begin
  // Obtains the collection of project test items
  TestItems := Project.TestItems;
  // Defines the total number of test items in the project
  Count := TestItems.ItemCount;
  // Iterates through the project’s test items
  for i := 0 to Count - 1 do
    ProcessTestItem(TestItems.TestItem(i));
end;

C++Script, C#Script

function Test()
{
  var i, TestItems, Count;
  // Obtains the collection of project test items
  TestItems = Project["TestItems"];
  // Defines the total number of test items in the project
  Count = TestItems["ItemCount"];
  // Iterates through the project’s test items
  for (i = 0; i < Count; i++)
    ProcessTestItem(TestItems["TestItem"](i));
}

function ProcessTestItem(ATestItem)
{
  // Posts the test item name
  Log["AppendFolder"](ATestItem["Name"]);
  // If the test item contains child items, iterates through them
  for (var i = 0; i < ATestItem["ItemCount"]; i++)
    ProcessTestItem(ATestItem["TestItem"](i));
  Log["PopLogFolder"]();
}

See Also

Test Items Page
Project.TestItems

Highlight search results