Timeout Property

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

Description

Specifies the maximum execution time for the test item in minutes. The property corresponds to the Timeout column of the project editor’s Test Items page.

A zero value for Timeout means that timeout is ignored. If Timeout is greater than 0 and the test item’s execution time exceeds the Timeout value, TestComplete generates the OnTimeout event, stops the item execution and considers the item as failed.

Declaration

ProjectTestItem_COMAccessObj.Timeout

Read-Write Property Integer
ProjectTestItem_COMAccessObj An expression, variable or parameter that specifies a reference to a ProjectTestItem_COMAccess object

Applies To

The property is applied to the following object:

Property Value

An integer value that specifies the maximum execution time for the test item.

Example

The following example demonstrates how to access the project’s test item collection from a Visual Basic or C# application. The sample code uses the ProjectTests_COMAccess object’s properties to obtain the ProjectTestItem_COMAccess objects that provide a program interface to the project test items. The example displays a tree structure corresponding to the project’s test item collection structure.

Visual Basic

Sub Test()

  Dim TestCompleteApp As TestCompleteApplication
  Dim IntegrationObject As ItcIntegration
  Dim LastResult As ItcIntegrationResultDescription

  ' Creates the application object
  Set TestCompleteApp = CreateObject("TestComplete.TestCompleteApplication.14")

  ' Obtains the integration object
  Set IntegrationObject = TestCompleteApp.Integration

  ' Opens the project
  IntegrationObject.OpenProjectSuiteEx "C:\Work Folder\TestSuite\TestSuite.pjs"

  ' Needed to process errors
  Err.Clear
  On Error GoTo Err_Label

    ' Obtains the ProjectTests_COMAccess object
    ' That provides a program interface to the project's test item collection
    Set ProjectItems = IntegrationObject.TestSuite("TestProject")

    ' Determines the number of test items the project contains
    ItemsCount = ProjectItems.Count

    ' Iterates through the project’s test items
    ' And displays them in the tree view
    For i = 0 To ItemsCount - 1
      Set TestItem = ProjectItems.TestItem(i)
      Call PopulateItem(TestItem)
    Next

  Err_Label:
    ' Processes errors
    If Err.Number <> 0 Then
      MsgBox Err.Description, vbCritical, "Error"
    End If

  ' Closes TestComplete
  TestCompleteApp.Quit

End Sub

Public Sub PopulateItem(ATestItem)

  Dim ANode As Node

  ' Obtains the parent item for the current test item
  Set PTestItem = ATestItem.ParentTestItem

  If Not PTestItem Is Nothing Then
    Set ANode = MainForm.ItemsTree.Nodes.Add(PTestItem.Name, tvwChild, ATestItem.Name, ATestItem.Name)
  Else
    Set ANode = MainForm.ItemsTree.Nodes.Add(, , ATestItem.Name, ATestItem.Name)
  End If

  ' Checks whether the test item is enabled
  If ATestItem.Enabled Then
    Set TNode = MainForm.ItemsTree.Nodes.Add(ATestItem.Name, tvwChild, , "Enabled: " & CStr(ATestItem.Enabled))
  End If

  ' Checks whether the test item is a group
  If ATestItem.IsGroup Then
    Set GNode = MainForm.ItemsTree.Nodes.Add(ATestItem.Name, tvwChild, , "Is a group: True")
  Else
    ' Obtains the test item description
    Set TNode = MainForm.ItemsTree.Nodes.Add(ATestItem.Name, tvwChild, , "Description: " & ATestItem.Description)

    ' Obtains the maximum execution time for the test item
    Set TNode = MainForm.ItemsTree.Nodes.Add(ATestItem.Name, tvwChild, , "Timeout: " & CStr(ATestItem.Timeout))

    ' Defines how many times the test item will be executed
    Set TNode = MainForm.ItemsTree.Nodes.Add(ATestItem.Name, tvwChild, , "Count: " & CStr(ATestItem.Count))

    ' Obtains the test item’s StopOnError property
    StopOnError = ATestItem.StopOnError
    Set TNode = MainForm.ItemsTree.Nodes.Add(ATestItem.Name, tvwChild, , "On error: ")
    Select Case StopOnError
      Case 0
        TNode.Text = TNode.Text & "Continue running"
      Case 1
        TNode.Text = TNode.Text & "Stop project"
      Case 2
        TNode.Text = TNode.Text & "Stop current item"
      Case 3
        TNode.Text = TNode.Text & "Use project's On error property"
    End Select

    ' Obtains the test item’s StopOnException property
    StopOnException = ATestItem.StopOnException
    Set TNode = MainForm.ItemsTree.Nodes.Add(ATestItem.Name, tvwChild, , "On exception: ")
    Select Case StopOnError
      Case 0
        TNode.Text = TNode.Text & "Continue running"
      Case 1
        TNode.Text = TNode.Text & "Stop project"
      Case 2
        TNode.Text = TNode.Text & "Stop current item"
    End Select
  End If

  ' Checks whether the test item has child test items
  If ATestItem.ChildCount > 0 Then
    ' Iterates through the child items
    For i = 0 To ATestItem.ChildCount - 1
      Set CTestItem = ATestItem.ChildTestItem(i)
      Call PopulateItem(CTestItem)
    Next
  End If

End Sub

C#

using System.Runtime.InteropServices;
using TestComplete;



public partial class MainForm : Form
{
  public MainForm()
  {
    InitializeComponent();
  }

  private void btn_Connect_Click(object sender, EventArgs e)
  {
    const string TCProgID = "TestComplete.TestCompleteApplication.14";
    object TestCompleteObject = null;

    // Obtains access to TestComplete
    try
    {
      TestCompleteObject = Marshal.GetActiveObject(TCProgID);
    }
    catch
    {
      try
      {
        TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
      }
      catch
      {
      }
    }

    if (TestCompleteObject == null) return;

      // Obtains ITestCompleteCOMManager
      TestComplete.ITestCompleteCOMManager TestCompleteManager = (TestComplete.ITestCompleteCOMManager) TestCompleteObject;
      // Obtains the Integration object
      TestComplete.ItcIntegration IntegrationObject = TestCompleteManager.Integration;

      // We have a reference to the integration object
      // Now we can use its methods and properties to automate TestComplete

      // Loads the project suite
      IntegrationObject.OpenProjectSuiteEx("C:\\Work Folder\\TestSuite\\TestSuite.pjs");

      try
      {
        // Obtains the ProjectTests_COMAccess object providing a program interface to the project’s test item collection
        object ObjProjectItems = IntegrationObject.get_TestSuite("TestProject");
        TestComplete.ItcProjectTests_COMAccess ProjectItems = (TestComplete.ItcProjectTests_COMAccess)ObjProjectItems;
        // Determines the number of test items the project contains
        int Count = ProjectItems.Count;

        TreeView ItemsTree = new TreeView();
        ItemsTree.CheckBoxes = true;
        ItemsTree.ShowNodeToolTips = true;
        ItemsTree.Size = new Size(400, 200);
        ItemsTree.Top = 12;
        ItemsTree.Left = 12;

        // Iterates through the project’s test items
        // And displays them in the tree view
        for (var i = 0; i < Count; i++)
        {
          TestComplete.ItcProjectTestItem_COMAccess TestItem = ProjectItems.get_TestItem(i);
          TreeNode TN = ProcessItem(TestItem);
          ItemsTree.Nodes.Add(TN);
        }
        this.Controls.Add(ItemsTree);

      }
      catch (System.Runtime.InteropServices.COMException ex)
      {
          System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
      }
      finally
      {
          // Closes TestComplete
          TestCompleteManager.Quit();
          // Releases COM objects
          Marshal.ReleaseComObject(IntegrationObject);
          Marshal.ReleaseComObject(TestCompleteManager);
          Marshal.ReleaseComObject(TestCompleteObject);
      }
    }
  }

  public TreeNode ProcessItem(TestComplete.ItcProjectTestItem_COMAccess ATestItem)
  {
    TreeNode ATreeNode = new TreeNode(ATestItem.Name);
    string ToolTipText;

    // Obtains the parent test item of the current test item
    // And checks whether the parent item and the current item are enabled
    TestComplete.ItcProjectTestItem_COMAccess PTestItem = ATestItem.ParentTestItem;
    if (((PTestItem != null) && (PTestItem.Enabled) && (ATestItem.Enabled)) || ((PTestItem == null) && (ATestItem.Enabled)) )
      ATreeNode.Checked = true;
    // Checks whether the current test item is a group
    if (ATestItem.IsGroup)
    {
      ToolTipText = "Is a Group";
    }
    else
    {
      // Obtains the test item description
      ToolTipText = "Description: " + ((String.IsNullOrEmpty(ATestItem.Description)) ? "not specified" : ATestItem.Description) + "\r\n";
      TestComplete.TC_TEST_ERROR_PROCEESING_VALUE StopOnError = ATestItem.StopOnError;
      // Obtains the test item’s StopOnError property
      ToolTipText += "On error: ";
      switch (StopOnError)
      {
        case TestComplete.TC_TEST_ERROR_PROCEESING_VALUE.epvNone:
          ToolTipText += "Continue running\r\n";
          break;
        case TestComplete.TC_TEST_ERROR_PROCEESING_VALUE.epvProject:
          ToolTipText += "Stop project\r\n";
          break;
        case TestComplete.TC_TEST_ERROR_PROCEESING_VALUE.epvTestItem:
          ToolTipText += "Stop current item\r\n";
          break;
        case TestComplete.TC_TEST_ERROR_PROCEESING_VALUE.epvProjectDefault:
          ToolTipText += "Use project's On error property\r\n";
          break;
      }
      // Obtains the test item’s StopOnexception property
      TestComplete.TC_TEST_ERROR_PROCEESING_VALUE StopOnException = ATestItem.StopOnException;
      ToolTipText += "On Exception: ";
      switch (StopOnException)
      {
        case TestComplete.TC_TEST_ERROR_PROCEESING_VALUE.epvNone:
          ToolTipText += "Continue running\r\n";
          break;
        case TestComplete.TC_TEST_ERROR_PROCEESING_VALUE.epvProject:
          ToolTipText += "Stop project\r\n";
          break;
        case TestComplete.TC_TEST_ERROR_PROCEESING_VALUE.epvTestItem:
          ToolTipText += "Stop current item\r\n";
          break;
      }

      // Defines how many times the test item will be executed
      ToolTipText += "Count: " + ATestItem.Count + "\r\n";
      // Obtains the maximum execution time for the test item
      ToolTipText += "Timeout: " + ATestItem.Timeout + "\r\n";
    }

    ATreeNode.ToolTipText = ToolTipText;
    // Obtains the number of the current test item’s child items
    int Count = ATestItem.ChildCount;
    // Iterates through the child items
    for (var i = 0; i < Count; i++)
    {
      TestComplete.ItcProjectTestItem_COMAccess CTestItem = ATestItem.get_ChildTestItem(i);
      TreeNode CTreeNode = ProcessItem(CTestItem);
      ATreeNode.Nodes.Add(CTreeNode);

    }

    return ATreeNode;

  }
}

See Also

Working With TestComplete via COM - Overview
StopOnError Property
StopOnException Property

Highlight search results