StopOnException Property

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

Description

Use the TestItems.StopOnException property to specify what TestComplete should do when an unhandled exception occurs during a test run. This property corresponds to the On exception column of the Execution Plan editor.

If the Show a notification when an unhandled script exception occurs project option is enabled, TestComplete displays an informative message and ignores the test item’s On exception property.

Declaration

Project TestItemObj.StopOnException

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

An integer value indicating the chosen behavior of TestComplete in case of an exception. The following values are possible:

Constant Value Description
epvNone 0 Proceed with the test run as if no exception has occurred. Corresponds to the Continue running value of the test item’s On exception column in the Execution Plan editor.
epvProject 1 Stop the execution of the whole project. Corresponds to the Stop project value of the test item’s On exception column in the Execution Plan editor.
epvTestItem 2 Stop the execution of the current test item (including its child items and further iterations of the current item), and proceed with the execution of the subsequent sibling items. Corresponds to the Stop current item value of the test item’s On exception column in the Execution Plan editor.

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

Execution Plan Editor
Project Properties - Playback Options
StopOnError Property
Enabled Property (Specific to Project Object)
Timeout Property

Highlight search results