Delphi自动化测试
QTP测试Delphi应用程序
QTP的delphi插件安装后,还需要对被测程序进行配置才能正常使用。
方法如下:
You must perform the following steps for each application that you want to test.
To link to the MicDelphiAgent.pas module:
1. Add the <QuickTest Professional Installation folder>\dat\Extensibility\Delphi folder to your Delphi project search path or copy the contents of the <QuickTest Professional Installation folder>\dat\Extensibility\Delphi folder to your project folder.
2. Add MicDelphiAgent to the Uses section of your application's project file (project.dpr) as shown in the example below:
program flight;
uses
MicDelphiAgent,
Forms,
Windows;
($R*.RES)
begin
Application.Initialize
Application.Title :='Flight Reservation';
Application.Run;
end.
3. Compile your Delphi project.
Note: If your application includes the TwwDBGrid from InfoPower, you must add support for this grid as described in Configuring Support for TwwDBGrid.
Configuring Support for TwwDBGrid
If your application includes the TwwDBGrid from InfoPower, follow the following instructions to enable support for this grid.
1. Add MicWWSupport to the Uses section of your application's project file (project.dpr) after MicDelphiAgent, as shown in the example below:
program flight;
uses
MicDelphiAgent,
MicWWSupport,
Forms,
Windows;
($R*.RES)
begin
Application.Initialize
Application.Title :='Flight Reservation';
Application.Run;
end.
2. Recompile your application.
You are now ready to create and run tests on Delphi applications.
SilkTest测试Delphi应用程序
SilkTest support of Delphi applications
While SilkTest does not support Delphi controls "out of the box", virtually all of the Delphi objects can be class mapped to standard SilkTest controls. For instance:
[ClassMap]
DialogBox,0x50000044,0x50000044=Ignore
TBitBtn=PushButton
TButton=PushButton
TCheckBox=CheckBox
TComboBox=ComboBox
TDBCheckBox=CheckBox
TDBComboBox=ComboBox
TDBEdit=TextField
TDBListBox=ListBox
TDBLookupComboBox=ComboBox
TDBLookupListBox=ListBox
TDBMemo=TextField
TDBRadioGroup=Ignore
TEdit=TextField
TFlyingPanel=Toolbar
TGroupBox=StaticText
TGroupButton=RadioButton
TListBox=ListBox
TListView=ListView
TMaskEdit=TextField
TMemo=TextField
TPageControl=PageList
TPanel=Ignore
TRadioButton=RadioButton
TRadioGroup=Ignore
TRichEdit=TextField
TRicherEdit=TextField
TScrollBar=ScrollBar
TStatusBar=StatusBar
TTabControl=PageList
TTreeView=TreeView
TUpDown=UpDown
There are a few custom controls that don't respond to class mapping (such as TreeViews, Grids, and StaticText). However, TypeKeys and mouse events can be used on them.
GetContents() Seems to return nothing for TreeViews.
Notes
SilkTest can work with Delphi objects in a variety of ways. The amount of functionality you achieve depends on how deep you want to get involved. You can even create an extension (external) for Delphi objects. Delphi supports DLL calling, and you can use DLL's created in C/C++ in your Delphi application. Class mapping will work in many instances, but not with every object.
If class mapping doesn't work, you can try any of the following workarounds:
- Using SendMessage with the Clipboard
- Delphi is built with VCL. The Borland VCL (Visual Component Library) is similar to MFC in that all of the classes of objects that Delphi can create are in this library. Instead of C++ it is written in Object Pascal. Borland ships the VCL source code with the product. In the VCL source, you can go to the definition of the object class that you want to support for and add message handlers (windows API messages) for various messages that you define.
- For example, add a message handler that says that if any object of this class receives a message called "QAP_GetValue", get the contents of the listbox, send a message back to the process that sent the message, and send it the value. On the SilkTest side of things you define a new class to support the object and add a method that sends/receives the message to the supported object.
- For example, here is sample code of a message handler on the Delphi side:
procedure QAP_GetValue (var Msg: TMessageRecord);
var
ValueToReturn : string;
begin
CopyToClipBoard;
Msg.Result := true;
end;
- Here is sample code for the Window class on the 4Test side:
winclass DelphObj : Control
LIST OF STRING GetContents ()
if (SendMessage (this.hWnd, QAP_GetListContents, NULL, NULL))
return Clipboard.GetText ()
else
RaiseError (1, "Couldn't get the contents of {this},
SendMessageEvent not processed correctly")
- Using the Extension Kit, create a DLL that does the same thing as above, except passing values directly from application to application rather than relying on the clipboard. This method is preferred over the above because of speed and data type stability.
- Use low level 4Test events relying on coordinates to create methods. SilkTest low-level recording should only be used when you want to use recording rather than hand scripting.
TestComplete测试Delphi应用程序
With TestComplete you can test almost any Windows application including those created with Borland Delphi ver. 3 and later.
- Borland Delphi v. 3.0 - 7.0.
- Borland Delphi 2005 and 2006 for Win32.
- CodeGear Delphi 2007 and 2009 for Win32.
- Embarcadero Delphi 2010 for Win32.
Using Debug Info Agent With Delphi Applications
Debug Info Agent™ exposes public, published, protected and private members of objects in Delphi Open Applications as soon as the application is compiled with debug information. This topic explains how to include debug information into applications created with Borland Delphi v. 3 - 7 or Borland Delphi 2005 for Win32. To learn how to prepare applications created with other Delphi versions, see Implementing Debug Info Agent™ Support in Applications.
The Delphi compiler generates debug information in the TD32 format, which is compiled into the application’s binary modules. However, it is possible to extract debug information into separate .tds files using TestComplete’s StripTDS utility.
Debug Info Agent™ can work with both formats. However, we recommend that you create external .tds files for release builds of your products. This will decrease the overall size of your application. The TD32 format of debug information can be used for intermediate or special builds.
Below are detailed instructions on changing the project options to use the desired format of debug information.
External Debug Information (TDS Files)
The .tds files are created based on executables and DLLs compiled with TD32 debug information included. To remove debug information from modules and store them in separate .tds files, you can use the StripTDS utility that is shipped with TestComplete.
So, to create .tds files, you should first compile the tested Delphi application with debug information and then process the compiled modules with the StripTDS utility. Below are detailed steps:
- Change the project settings to compile the application with TD32 debug information:
- Open your project in Borland Delphi.
- Select Project | Options from Delphi’s main menu. This will open the Project Options dialog.
- Switch to the Compiler tabbed page and check the Debug information and Local symbols options in the Debugging group:
Note: |
It is possible to keep the Local symbols disabled, but in this case the names of some method parameters will not be displayed in the Object Browser panel. |
-
- Switch to the Linker tab and enable the Include TD32 debug info option in the EXE and DLL options group:
-
- Press OK to save the changes and close the Project Options dialog.
- Re-build the application.
- Apply the StripTDS utility to each compiled executable and DLL. For example, to process all EXE and DLL files in the C:\MyApp folder and its subfolders, you can use the following command line:
StripTDS.exe -r -w C:\MyApp\*.exe;C:\MyApp\*.dll
The utility will remove debug information from the executable files and save it to separate .tds files. The utility only works with those sections in the binary file that contain debug information. It does not change the code and data sections, so your module will work as it was designed. For more information about the modifications and command-line arguments of the StripTDS utility, see About StripTDS.
Some notes concerning this approach:
- The .tds files containing debug information must reside in the same folders that the appropriate modules of the tested application.
- Even if the application is compiled with the Local symbols option enabled, the names of some method parameters may not be displayed in the Object Browser. If viewing parameter names is important to you (for instance, if you are developing new tests), compile the tested Delphi application with internal TD32 debug information (see below).
- There is no need to distribute the generated .tds files with your application.
Internal Debug Information (TD32)
To compile your Delphi application with embedded TD32 debug information, follow these steps:
- Choose Project | Options from the main menu.
- In the ensuing Project Options dialog, switch to the Compiler tabbed page. Enable the Debug information option in the Debugging group to include debug information:
- To see the names of method parameters in the Object Browser panel, turn off the Optimization option and enable the Local symbols option. When using Delphi 5.0 or later, also enable the Use Debug DCUs option:
- Switch to the Linker tab and enable the Include TD32 debug info option in the EXE and DLL options group:
- It is recommended that you turn off the Build with runtime packages option on the Packages tabbed page:
The reason for unchecking this option is as follows: In order for Debug Info Agent™ to have access to VCL objects, methods and properties provided by Delphi packages, the latter must be compiled with debug information. However, runtime packages are compiled without debug information by default. When the Build with runtime packages option is turned on, the compiler does not include the packages’ VCL code into the executable, so the methods and properties of VCL objects provided by the packages will be unavailable to TestComplete. By unchecking this option, you force the compiler to include the packages’ code into the executable and thus generate debug information for that code as well.
- Once you have completed the above steps, press OK to save the changes and close the Project Options dialog.
- Re-compile the application.
Remember to recompile the release version of your application without TD32 debug information in order to reduce the application size.