Not long ago I tested a Delphi Open Application that contained a lot of objects which I didnt need to test. All of these objects were displayed in the Object Browser panel, which annoyed me. I became much happier when I found out that in TestComplete 4.23 its possible to filter objects in Delphi Open Applications. This can be done by modifying the tcOpenAppClasses.pas file that is compiled into Delphi Open Applications. I tried it and Im very satisfied with the results. Now TestComplete does not process the objects I do not need to test, and as a result, my scripts run much faster. In this blog, Ill describe how you can modify the tcOpenAppClasses.pas file for your Delphi application.
Creating a sample application
I cannot use my application as a sample, since its too complex. Ill tell you how to filter objects in a Delphi Open Application using a sample application that you can download from here.
First, create a new application project in Delphi. Name the project DelphiFiltration and save it to the <Program Files>Automated QATestComplete 4SamplesOpen AppsDelphiFiltration folder.
Now lets make the application Open. To do this, you should include the tcOpenApp.pas, tcOpenAppClasses.pas and tcPublicInfo.pas files in it. Here is an excerpt from TestCompletes help system that explains how to create a Delphi Open Application:
To create an Open Application:
- Include the files tcOpenApp.pas, tcOpenAppClasses.pas and tcPublicInfo.pas in your project. These files are located in the <TestComplete>Open AppsDelphi&BCB folder. Each of these files refers to the ver.inc file that also resides in the previously mentioned folder. The ver.inc file defines conditional symbols for different versions of Borland Delphi and C++Builder. tcOpenApp.pas uses the tcOpenAppHook dynamic link library. The TestComplete installation places this DLL into the <TestComplete>BinExtensions folder.
To add files to your project, use Delphis or BCBs Add to project dialog. To activate the dialog, select the Project | Add to Project menu item or press SHIFT-F11. (C++Builder will compile Delphi Pascal source files.)
- Recompile your project.
After you compiled your Open Application, launch it and switch to TestCompletes Object Browser to see whether the application has become Open (the Object Browser displays the scales next to the DelphiFiltration process in the Object Tree).
Creating objects to be filtered
Lets simulate a situation in which a lot of objects that we are not going to test are created. To do this, add a number of
TMenuItem objects to the application. Save references to these objects to the
MenuItemsArr arrays that are members of the
TForm1 class. You can perform these actions within the
OnCreate event handler:
Dont forget to delete the created objects within the
OnDestroy event handler:
The number of created
TMenuItem objects is specified by the
The code of the uMain unit now looks like this:
Now lets run the application under test and TestComplete. Make sure that TestCompletes Object Browser displays a lot of
TMenuItem objects. The objects belong to the
VCLObject("Form1") object of the DelphiFiltration process.
Now its time to filter the objects. To do this, we will tcOpenAppClasses.pas file. Copy this file from its original location - <TestComplete>Open AppsDelphi&BCBtcOpenAppClasses.pas - to your Delphi project folder (this will keep the original version of the file unchanged).
Correct the reference to the tcOpenAppClasses.pas file in your project file.
Open the tcOpenAppClasses.pas file for editing in Delphis Code Editor. Find the TtcComponentInfoProvider.GetChildComponent method. It has the following code:
This method provides information about Open Application objects to TestComplete (it returns a reference to an object). To make objects invisible to TestComplete, simply return
nil for them. Our example contains the
TMenuItem objects, which we do not need for testing. To hide these objects for TestComplete, write the following code for the method:
Now compile and run the application. Look at the Object Browser panel; the
VCLObject("Form1") object of the DelphiFiltration process does not contain the
TMenuItem objects and the
VCLObject("Form1") now opens a lot faster. So, if you filter your application objects this way, TestComplete will execute your scripts a lot faster.