ProjectIntegration Object

Applies to TestComplete 14.0, last modified on January 23, 2019

Description

The ProjectIntegration object represents the project opened in TestComplete. It provides methods and properties that let you manage the collection of scripts included in the project. To obtain the ProjectIntegration object, connect to TestComplete via COM and use the Project property of the TestComplete Integration object. For more information, see Working With TestComplete via COM.

Members

Example

The following example demonstrates how you can work with script units of the project currently opened in TestComplete.

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
  ProjectPath = "C:\Work Folder\TestSuite\TestSuite.pjs"
    IntegrationObject.OpenProjectSuite (ProjectPath)

  ' Checks whether the project suite was opened
  ' If the project suite cannot be opened, closes TestComplete
  If Not IntegrationObject.IsProjectSuiteOpened Then
    MsgBox "The project suite was not opened."
    ' Closes TestComplete
    TestCompleteApp.Quit
    Exit Sub
  End If

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

    ' Obtains the ProjectIntegration object
    Set ProjectIntegration = IntegrationObject.Project("TestProject_VB")
    ' Specifies the script unit file
    UnitPath = "C:\Work Folder\TestSuite\TestProject_VB\Script\Test4_VB.svb"
    ' Checks whether the project contains the specified script unit
    If ProjectIntegration.HasUnit(UnitPath) Then
      ' If the project contains the unit
      ' Displays an informative message
      MsgBox "The project already contains the specified script unit"
    Else
      ' If the project does not contain the unit
      ' Adds the unit to the project
      ProjectIntegration.AddUnit (UnitPath)

      …

      ' Removes the added unit from the project
      ProjectIntegration.RemoveUnit (UnitPath)
    End If

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

  ' Closes TestComplete
  TestCompleteApp.Quit

End Sub

C#

// Add the following lines to your code
using System.Runtime.InteropServices;
using TestComplete;


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

  private void btn_Connect_Click(object sender, EventArgs e)
  {
    const string TCProgID = "TestComplete.TestCompleteApplication.14";
    string ProjectSuitePath = "C:\\Work Folder\\TestSuite\\TestSuite.pjs";
    string ProjectPath = "C:\\Work Folder\\TestSuite\\TestProject_CS";
    string ProjectName = "TestProject_CS";
    object TestCompleteObject = null;
    string FilePath;

    // 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 Integration object
    TestComplete.ItcIntegration IntegrationObject = TestCompleteManager.Integration;
    // Loads the project suite
    IntegrationObject.OpenProjectSuite(ProjectSuitePath);
    // Checks whether the project suite was opened
    if (!IntegrationObject.IsProjectSuiteOpened())
    {
      System.Windows.Forms.MessageBox.Show("Could not open the project suite.");
      // Closes TestComplete
      TestCompleteManager.Quit();
      // Releases COM objects
      Marshal.ReleaseComObject(IntegrationObject);
      Marshal.ReleaseComObject(TestCompleteManager);
      Marshal.ReleaseComObject(TestCompleteObject);
      return;
    }

    try
    {
      // Obtains ProjectIntegration object
      TestComplete.ItcProjectIntegration Project = IntegrationObject.get_Project(ProjectName);

      // Shows the Open File dialog allowing to select a script unit to add to the project
      OpenFileDialog.InitialDirectory = ProjectPath + "\\Script";
      OpenFileDialog.Filter = "C#Script files|*.scs";
      if (OpenFileDialog.ShowDialog() == DialogResult.OK)
      {
        FilePath = OpenFileDialog.FileName;
        if (Project.get_HasUnit(FilePath))
          // If the project already contains the selected unit
          // Displays the informative message
          MessageBox.Show("The project already contains this script unit");
        else
        {
          // If the project does not contain the selected unit
          // Adds the unit to the project
          Project.AddUnit(FilePath);

          …

          // Removes the added unit from the project
          Project.RemoveUnit(FilePath);
        }
      }
    }
    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

Project Property
Integration Object
Working With TestComplete via COM - Overview

Highlight search results