denolfe
12 years agoOccasional Contributor
TestExecute via COM, Unable to find namespace 'TestExecute'
I am attempting to integrate TestExecute with our C# application via COM objects.
I have followed the documentation as closely as possible from here.
1. I have added the assembly references to my solution (AutomatedQA.script.dll and AutomatedQA.TestComplete.CSConnectedApp.dll)
2. I have added the necessary "using" statements to my code
using AutomatedQA.script;
using AutomatedQA.TestComplete;
However, I still have an unrecognized namespace "TestExecute" when I try to get the TestExecuteManager and Integration object. These are the only 2 problem lines. All other references look to be valid.
Is the documentation still valid? Am I doing this incorrectly?
private void RunTestGroup(string testName)
{
const string TEProgID = "TestExecute.TestExecuteApplication.9";
object TestExecuteObject = null;
try
{
TestExecuteObject = Marshal.GetActiveObject(TEProgID);
}
catch
{
try
{
TestExecuteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TEProgID));
}
catch {}
}
if (TestExecuteObject == null) return;
/*
* These are the problem lines
*/
// Obtains ITestCompleteCOMManager
TestComplete.ITestCompleteCOMManager TestExecuteManager = (TestComplete.ITestCompleteCOMManager)TestExecuteObject;
// Obtains Integration object
TestComplete.ItcIntegration IntegrationObject = TestExecuteManager.Integration;
IntegrationObject.OpenProjectSuite(@"C:\TestComplete\Tests\SalesPadTest\SalesPadTest.pjs");
while (!IntegrationObject.IsRunning())
System.Threading.Thread.Sleep(1000);
if (!IntegrationObject.IsProjectSuiteOpened())
{
Console.WriteLine("Could not open the project suite. EXITING.");
// Closes TestExecute
TestExecuteManager.Quit();
// Releases COM objects
Marshal.ReleaseComObject(IntegrationObject);
Marshal.ReleaseComObject(TestExecuteManager);
Marshal.ReleaseComObject(TestExecuteObject);
return;
}
try
{
// Runs the test
IntegrationObject.RunProjectTestItem(testName);
// Waits until testing is over
while (IntegrationObject.IsRunning())
System.Threading.Thread.Sleep(1000);
// Check the results
switch (IntegrationObject.GetLastResultDescription().Status)
{
case TestComplete.TC_LOG_STATUS.lsOk:
Console.WriteLine("The test run finished successfully.");
break;
case TestComplete.TC_LOG_STATUS.lsWarning:
Console.WriteLine("Warning messages were posted to the test log.");
break;
case TestComplete.TC_LOG_STATUS.lsError:
Console.WriteLine("Error messages were posted to the test log.");
break;
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
Console.WriteLine("An exception occurred: " + ex.Message);
}
finally
{
// Closes TestExecute
TestExecuteManager.Quit();
// Releases COM objects
Marshal.ReleaseComObject(IntegrationObject);
Marshal.ReleaseComObject(TestExecuteManager);
Marshal.ReleaseComObject(TestExecuteObject);
}
}
I have followed the documentation as closely as possible from here.
1. I have added the assembly references to my solution (AutomatedQA.script.dll and AutomatedQA.TestComplete.CSConnectedApp.dll)
2. I have added the necessary "using" statements to my code
using AutomatedQA.script;
using AutomatedQA.TestComplete;
However, I still have an unrecognized namespace "TestExecute" when I try to get the TestExecuteManager and Integration object. These are the only 2 problem lines. All other references look to be valid.
Is the documentation still valid? Am I doing this incorrectly?
private void RunTestGroup(string testName)
{
const string TEProgID = "TestExecute.TestExecuteApplication.9";
object TestExecuteObject = null;
try
{
TestExecuteObject = Marshal.GetActiveObject(TEProgID);
}
catch
{
try
{
TestExecuteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TEProgID));
}
catch {}
}
if (TestExecuteObject == null) return;
/*
* These are the problem lines
*/
// Obtains ITestCompleteCOMManager
TestComplete.ITestCompleteCOMManager TestExecuteManager = (TestComplete.ITestCompleteCOMManager)TestExecuteObject;
// Obtains Integration object
TestComplete.ItcIntegration IntegrationObject = TestExecuteManager.Integration;
IntegrationObject.OpenProjectSuite(@"C:\TestComplete\Tests\SalesPadTest\SalesPadTest.pjs");
while (!IntegrationObject.IsRunning())
System.Threading.Thread.Sleep(1000);
if (!IntegrationObject.IsProjectSuiteOpened())
{
Console.WriteLine("Could not open the project suite. EXITING.");
// Closes TestExecute
TestExecuteManager.Quit();
// Releases COM objects
Marshal.ReleaseComObject(IntegrationObject);
Marshal.ReleaseComObject(TestExecuteManager);
Marshal.ReleaseComObject(TestExecuteObject);
return;
}
try
{
// Runs the test
IntegrationObject.RunProjectTestItem(testName);
// Waits until testing is over
while (IntegrationObject.IsRunning())
System.Threading.Thread.Sleep(1000);
// Check the results
switch (IntegrationObject.GetLastResultDescription().Status)
{
case TestComplete.TC_LOG_STATUS.lsOk:
Console.WriteLine("The test run finished successfully.");
break;
case TestComplete.TC_LOG_STATUS.lsWarning:
Console.WriteLine("Warning messages were posted to the test log.");
break;
case TestComplete.TC_LOG_STATUS.lsError:
Console.WriteLine("Error messages were posted to the test log.");
break;
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
Console.WriteLine("An exception occurred: " + ex.Message);
}
finally
{
// Closes TestExecute
TestExecuteManager.Quit();
// Releases COM objects
Marshal.ReleaseComObject(IntegrationObject);
Marshal.ReleaseComObject(TestExecuteManager);
Marshal.ReleaseComObject(TestExecuteObject);
}
}