Forum Discussion

denolfe's avatar
denolfe
Occasional Contributor
11 years ago

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);


            }


        }











6 Replies

  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Elliot,



    The reference you must add is not to a dll but to a COM object. Please see the attached screenshot (VS 2010 Add Reference dialog).



    Sincerely
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Elliot,



    It seems that your problem is at :

     // Runs the test

    IntegrationObject.RunProjectTestItem(testName);



    It shouldn't even compile because RunProjectTestItem takes two arguments only:

    void RunProjectTestItem(string ProjectName, string ProjectTestItemName);



    Sincerely
  • denolfe's avatar
    denolfe
    Occasional Contributor
    Simon,



    Thank you for pointing that out.  I most likely would have run into that after resolving the current issue



    However, as it stands right now I can't compile due to the following 2 lines:

    TestComplete.ITestCompleteCOMManager TestExecuteManager = (TestComplete.ITestCompleteCOMManager)TestExecuteObject;

    TestComplete.ItcIntegration IntegrationObject = TestExecuteManager.Integration;



    I am getting the Error:

    "The type or namespace name 'TestComplete' could not be found (are you missing a using directive or an assembly reference?)" on the 3 mentions of TestComplete



    Anything look wrong with those? It is right from the documentation.
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Elliot,



    With TC 9.2, the following statement, at the beginning of your file, will definitely help:



    using TestComplete;



    Sincerely
  • denolfe's avatar
    denolfe
    Occasional Contributor
    Simon, thank you for continuing to troubleshoot with me. I am running TE 9.3 and have the following 2 statements




    using AutomatedQA.script;


    using AutomatedQA.TestComplete;



    Both are recognized by Visual Studio as valid. Putting "using TestComplete" oddly enough is not recognized.  



    Admittedly, I have never done any 3rd party dll referencing before.  Is there anything that must be done beyond adding the references to the project and the necessary using statements? It looks like the AutomatedQA.script.dll is being referenced correctly as all of those lines are recognized.  However, anything for the AutomatedQA.TestComplete.CSConnectedApp.dll is not. I did however do the same exact process for adding both.



  • denolfe's avatar
    denolfe
    Occasional Contributor
    That was it! It seems I was making it much more complicated than it actually was. Thank you so much for your help, Simon!