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.
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.
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