TestItem Object (Specific to Project Object)

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

The TestItem object provides access to a test item defined in your project and allows you to get the test item’s property values. Note that all of the TestItem object properties are read-only and cannot be changed during the test run. To set up the project’s test items, use the Execution Plan editor of the project.

To access a project’s top-level test item by its index, use the TestItems.TestItem property. To access a child test item, use the TestItem property of its parent test item.

Members

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

Tests, Test Items, and Test Cases
Execution Plan Editor
TestItem Property (Specific to Project Object)

Highlight search results