ProjectIntegration Object

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

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

  ' Obtains the integration object
  Set IntegrationObject = TestCompleteApp.Integration

  ' Opens the project
  ProjectPath = "C:\Work Folder\TestSuite\TestSuite.pjs"
    IntegrationObject.OpenProjectSuiteEx (ProjectPath)

  ' 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.15";
    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.OpenProjectSuiteEx(ProjectSuitePath);
    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