An Object Model is a structural representation of objects that comprise the implementation of a system or application. Automation enables software packages to expose their unique features to scripting tools and other applications. Usually, Automation uses the Component Object Model (COM). A critical aspect of COM is, how clients and servers interact. A COM server is any object that provides services to clients; these services are in the form of COM interface implementations like Properties, Methods, Events and their relationships. Which can be called by any client that is able to get a pointer to one of the interfaces on the server object.

TestComplete is also a COM Server and its different methods and properties are exposed by its COM interface which can be accessed by other applications and scripting tools to control it from outside. In this post, we will see how to interact with TestComplete from outside via COM. However, there are other ways as well to interact with TestComplete, which we will discuss in another post for TestComplete: Command-Line.

The very first step is to Connect to TestComplete COM Server. The connection can be created by calling the “CreateObject” function. The “CreateObject” function, creates and returns a reference to a COM object.  It accepts two arguments one mandatory and another optional.

CreateObject(ServerName.TypeName, RemoteServerName)

ServerName is the name of the application that provides the object or the application which provides the Com interface. We can call them automation servers. TypeName is the type or class of object to be created. RemoteServerName is used to create the object on a remote server. For TestComplete it is ‘TestComplete’ as Servername and ‘TestCompleteApplication’ as TypeName.

Set objTestComplete = CreateObject("TestComplete.TestCompleteApplication")

This will launch a new instance of TestComplete which will be hidden. To make it visible, assign the value ‘true’ to the ‘Visible’ property.

objTestComplete.Visible = True

Integration property returns a reference to the ItcIntegration object (Integration object for short). It provides access to a subset of higher-level functions specifically engineered to let users perform most typical actions over TestComplete with ease.

Set objIntegration = objTestComplete.Integration
objIntegration.OpenProjectSuite "C:\TC\SampleTest.pjs"

This will open the project suite located at the mentioned path. Use one of the following methods of the Integration object to run the test:

  • RunProjectSuite – Initiates the run of the project suite opened in TestComplete.
  • RunProject – Initiates the run of tests provided by the specified project.
  • RunProjectItem – Initiates the run of tests provided by the specified project item.
  • RunProjectTestItem – Initiates the test runs provided by the specified project test item.
  • RunTestByName – Initiates the run of a test having the specified name.
See also  How TestComplete identify Objects

Before calling any of these routines make sure TestComplete is not executing any tests. You can do this, using the IsRunning method. If you call this when TestComplete is running tests, an error will occur. Each of these methods returns after the test run was started or after the tests failed to start. They do not pause the program execution until the test run is over. To wait for the test end, you can check the result of the IsRunning method in a loop. To call a specific routine RunRoutine or RunRoutineEx methods of Integration object can be used.

  • RunRoutineEx – lets you call routines containing parameters.
  • RunRoutine – can call routines or script functions that do not use parameters.
RunRoutine(ProjectName, UnitName, RoutineName)

RunRoutineEx(ProjectName, UnitName, RoutineName, Parameters)

below are some more methods of Integration objects which can be used while automating TestComplete:

  • ExportResults – to export the results of the last test run.
  • Stop or Halt – to stop the test that is running in TestComplete.
  • GetLastResultDescription – to check whether the last test run finished successfully.

the VBS code below demonstrates how to automate TestComplete.

Dim objTestComplete   
Dim objIntegration   
Dim objLastResult

' Creates the application object   
Set objTestComplete = CreateObject("TestComplete.TestCompleteApplication")

' Obtains the integration object   
Set objIntegration = objTestComplete.Integration

' Opens the project   
objIntegration.OpenProjectSuite "C:\TC\Examples\TestExample.pjs"

' Checks whether the project suite was opened   
If objIntegration.IsProjectSuiteOpened Then    
   ' Starts the project run    
   objIntegration.RunProject "TestExample"

   ' Waits until the test is over  
   n = 0     
   While objIntegration.IsRunning       
      n = n+1     
   Wend

   ' Exports the results   
   objIntegration.ExportResults("C:\TC\Examples\Logs\Test_Results.mht", true)   
End If

' Closes TestComplete   
objTestComplete.Quit

References:
SmartBear
Microsoft MSDN

10 COMMENTS

  1. This is really great blog and useful tips…i guess every automation expert would benefit from this blog…great work Saket…keep up the good work.

  2. Hi saket,

    But i want to pass the path for Project name also instead of only project name.
    “IntegrationObject.RunRoutine sProjectName, sUnitName, sRoutineName” method doesnot work if we pass project path instead of project name.. is there any other method which accepts so?

  3. Hi Shireesha,
    Sorry, if I am not getting your question correctly. by Path for project name – you mean it is stored at different location than the project suite?
    In that case as well, the project is still associated with it and it shows up there in project explorer. write exactly the same name as you see in Project Explorer.

  4. Another issue:

    I am trying to pass multiple project routines to IntegrationObject.RunRoutine using excel parameterization. Problem arises where human intervention is required when run time error occurs to click on Test complete pop describing the run time error.

    Can we handle that window also using vb script so that my miltiple project routines run at a time without human intervention?

  5. Hi Shireesha,

    You can use the error handling techniques like “on error resume next” to handle the error pop up that arises during run time.

  6. In such RunTime erorrs how would i log the result as “Fail due to RUn Time error” in my Result using COM-Integration object?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.