ProjectSuiteTests_COMAccess Object

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

Description

The ProjectSuiteTests_COMAccess object provides a program interface for a project suite's test items collection. To obtain the ProjectSuiteTests_COMAccess object, connect to TestComplete via COM and use the TestSuite property of the TestComplete Integration object. For more information, see Working With TestComplete via COM - Overview.

Members

Example

The following example obtains the ProjectSuiteTests_COMAccess object and uses its properties to obtain the ProjectSuiteTestItem_COMAccess objects corresponding to individual project suite test items (projects). It displays project suite test items' properties and runs the test items one after another.

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.15")

  ' Obtains the integration object
  Set IntegrationObject = TestCompleteApp.Integration

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

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

    ' Obtains the ProjectSuiteTestItems_COMAccess object
    Set PSTests = IntegrationObject.TestSuite("")
    ' Determines the number of test items (projects) the project suite contains
    Count = PSTests.Count

    If Count > 0 Then

      ' Iterates through the project suite test items
      For i = 0 To Count - 1
        ' Obtains the project suite test item
        Set PSTestItem = PSTests.TestItem(i)

        ' Checks whether the project suite test item is enabled
          If PSTestItem.Enabled Then
            ' Obtains the name of the test item (the project’s name)
            ProjectName = PSTestItem.ProjectName
            ' Obtains the file name of the project
            Location = PSTestItem.ProjectLocation
            ' Obtains the ProjectTests_COMAccess object corresponding to the project
            Set ProjectItem = PSTestItem.Project
            ' Obtains the number of project test items
            ChildItems = ProjectItem.Count
            ' Defines whether the project suite will be stopped if the project fails
            StopOnError = PSTestItem.StopOnError
            ' Obtains the maximum execution time for the current project
            Timeout = PSTestItem.Timeout
            ' Obtains the project description
            Description = PSTestItem.Description
            Info = "Name: " & ProjectName & VbCrLf & _
              "Location: " & Location & vbCrLf & _
              "Test items: " & ChildItems & vbCrLf & _
              "Stop on error: " & StopOnError & vbCrLf & _
              "Timeout: " & Timeout & vbCrLf & _
              "Description: " & Descriptiong & vbCrLf

            ' Displays project suite test item information
            UserForm1.Label1.Caption = Info

            ' Runs the project suite test item
            IntegrationObject.RunProject ProjectName
            ' Waits until the execution is over
            While IntegrationObject.IsRunning
              DoEvents
            Wend

            ' Checks the results
            Set LastResult = IntegrationObject.GetLastResultDescription
            Select Case LastResult.Status
              Case 0: MsgBox "The project run has finished successfully."
              Case 1: MsgBox "Warning messages were posted to the test log."
              Case 2: MsgBox "Error messages were posted to the test log."
            End Select

          End If

      Next

    End If

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

  ' Closes TestComplete
  TestCompleteApp.Quit

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.15";
    object TestCompleteObject = null;
    const string ProjectSuitePath = "C:\\Work Folder\\TestSuite\\TestSuite.pjs";
    // 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(ProjectSuitePath);

    try
    {
      // Obtains the ProjectSuiteTestItems_COMAccess object
      object PSTestItems = IntegrationObject.get_TestSuite("");
      TestComplete.ItcProjectSuiteTests_COMAccess NewPSTestItems = null;
      NewPSTestItems = (TestComplete.ItcProjectSuiteTests_COMAccess)PSTestItems;

      // Determines the number of test items (projects) the project suite contains
      int Count = NewPSTestItems.Count;

      if (Count > 0)
      {
        // Iterates through the project suite test items
        for (var i = 0; i < Count; i++)
        {
          //Obtains the project suite test item
          TestComplete.ItcProjectSuiteTestItem_COMAccess PSTestItem = NewPSTestItems.get_TestItem(i);
          // Checks whether the project suite test item is enabled
          if (PSTestItem.Enabled)
          {
            // Obtains the ProjectTests_COMAccess object corresponding to the project
            TestComplete.ItcProjectTests_COMAccess ProjectItem = PSTestItem.Project;

            // Displays project suite test item information

            // Obtains the name of the test item (the project’s name)
            InfoTextBox.Text = "Name: " + PSTestItem.ProjectName + "\r\n";
            // Obtains the file name of the project
            InfoTextBox.Text += "Location: " + PSTestItem.ProjectLocation + "\r\n";
            // Obtains the number of project test items
            InfoTextBox.Text += "Test items: " + ProjectItem.Count + "\r\n";
            // Defines whether the project suite will be stopped if the project fails
            InfoTextBox.Text += "Stop on error: " + PSTestItem.StopOnError + "\r\n";
            // Obtains the maximum execution time for the current project
            InfoTextBox.Text += "Timeout: " + PSTestItem.Timeout + "\r\n";
            // Obtains the project description
            InfoTextBox.Text += "Description: " + PSTestItem.Description + "\r\n";
            // Runs the project suite test item
            IntegrationObject.RunProject(PSTestItem.ProjectName);

            // Waits until the execution is over
            while (IntegrationObject.IsRunning())

            Application.DoEvents();

            // Checks the results
            switch (IntegrationObject.GetLastResultDescription().Status)

            {
              case TestComplete.TC_LOG_STATUS.lsOk:
                System.Windows.Forms.MessageBox.Show(this, "The project run has finished successfully.");
                break;
              case TestComplete.TC_LOG_STATUS.lsWarning:
                System.Windows.Forms.MessageBox.Show(this, "Warning messages were posted to the test log.");
                break;
              case TestComplete.TC_LOG_STATUS.lsError:
                System.Windows.Forms.MessageBox.Show(this, "Error messages were posted to the test log.");
                break;
            }
          }
          InfoTextBox.Clear();
        }
      }
    }
    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);
    }

  }
}

See Also

TestSuite Property
ProjectSuiteTestItem_COMAccess Object
ProjectTests_COMAccess Object
Working With TestComplete via COM - Overview
Tests, Test Items, and Test Cases

Highlight search results