Description
Use the TestItem
property to obtain access to individual test items of the ProjectSuiteTests_COMAccess collection that contains project suite test items.
Declaration
ProjectSuiteTests_COMAccessObj.TestItem(Index)
Read-Only Property | A ProjectSuiteTestItem_COMAccess object |
ProjectSuiteTests_COMAccessObj | An expression, variable or parameter that specifies a reference to a ProjectSuiteTests_COMAccess object | |||
Index | [in] | Required | Integer |
Applies To
The property is applied to the following object:
Parameters
The property has the following parameter:
Index
Specifies the index (zero-based) of the needed test item. The total number of items is specified by the Count
property.
Property Value
The property returns the ProjectSuiteTestItem_COMAccess
object corresponding to a specified test item of the project suite's test items collection.
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
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 suite
IntegrationObject.OpenProjectSuite "C:\Work Folder\TestSuite\TestSuite.pjs"
' 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 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 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;
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.OpenProjectSuite(ProjectSuitePath);
// Checks whether the project suite was opened
// If the project suite cannot be opened, closes TestComplete
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 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
Working With TestComplete via COM - Overview
Count Property
ProjectSuiteTestItem_COMAccess Object
Tests and Test Items