TestComplete provides you with access to individual objects of C++Builder applications, their internal properties and methods. The following sections describe how you can access these native properties and methods from your tests:
About Accessing Native Properties and Methods
Getting Access to C++Builder Applications’ Native Properties and Methods
About Accessing Native Properties and Methods
TestComplete identifies individual GUI objects in C++Builder applications and provides specialized methods and properties for automating various operations on these objects, getting object data, checking the state and so on. However, if these predefined properties and methods are insufficient for your testing needs, you can use native properties and methods of C++Builder objects to complete desired tasks. These are the same properties and methods that are available for use in the tested application’s source code as well as custom properties and methods implemented by the application developers. This way, you can perform almost any operations in the tested C++Builder application, even those that are not accessible via the application’s GUI.
TestComplete can expose only published methods and properties of VCL controls in 64-bit C++Builder applications. Public, protected and private members are not currently available. |
The Object Browser marks objects of C++Builder applications with the glyph. To view native properties and methods available for a C++Builder object, use the Object Spy or Object Browser in the Advanced view mode. Native properties and methods of C++Builder objects are displayed under the RTTI and Debug Agent categories. The RTTI category contains published properties, while the Debug Agent group includes public, protected and private members of an application’s objects (see Important Notes for details).
For more information on how to refer to objects in C++Builder applications, see Addressing Objects in C++Builder Applications.
Getting Access to C++Builder Applications’ Native Properties and Methods
By default, TestComplete provides you with access to C++Builder applications' published properties. You do not need to prepare your application in any special way to call these properties from your tests.
If you need to get access to an application’s public, protected and private members, you need to compile your application with debug information. For detailed instructions on how to compile an application with debug information with different versions of the C++Builder compiler, see Preparing C++Builder Applications for Testing.
Getting and Setting Native Object Properties
To access an object’s property in script code, you specify the property name after the object name using the dot operator ".
" (in VBScript, JScript, Python and DelphiScript projects) or the square bracket notation [" "]
(in C++Script and C#Script projects).
For example, you can get and set a C++Builder form’s title using its native Caption
property in the following way:
JavaScript, JScript
var title = Aliases.Orders.MainForm.Caption;
Aliases.Orders.MainForm.Caption = "New Window Title";
Python
title = Aliases.Orders.MainForm.Caption;
Aliases.Orders.MainForm.Caption = "New Window Title";
VBScript
Dim title
title = Aliases.Orders.MainForm.Caption
Aliases.Orders.MainForm.Caption = "New Window Title"
DelphiScript
procedure Test;
var title;
begin
…
title := Aliases.Orders.MainForm.Caption;
Aliases.Orders.MainForm.Caption := 'New Window Title';
…
end;
C++Script, C#Script
var title = Aliases["Orders"]["MainForm"]["Caption"];
Aliases["Orders"]["MainForm"]["Caption"] = "New Window Title";
In keyword tests, you can retrieve an object’s property value and save it to a test variable using the Set Variable Value operation. To change a property value, you can use the On-Screen Action operation to call the property’s [Set] method. For more information, see Getting and Setting Object Property Values.
You can also create checkpoints to verify values of native object properties.
Calling Native Object Methods
To call an object’s method from script code, you use the dot operator ".
" (in VBScript, JScript, Python and DelphiScript projects) or the square bracket notation [" "]
(in C++Script and C#Script projects) to specify the method name after the object name. For example, you can call the native GetChecked
method of a C++Builder button in the following way:
For example, in script code you can call the native GetChecked
method of a C++Builder button as follows:
JavaScript, JScript
Aliases.Orders.OrderForm.ButtonOK.GetChecked();
Python
Aliases.Orders.OrderForm.ButtonOK.GetChecked();
VBScript
Aliases.Orders.OrderForm.ButtonOK.GetChecked
DelphiScript
Aliases.Orders.OrderForm.ButtonOK.GetChecked();
C++Script, C#Script
Aliases["Orders"]["OrderForm"]["ButtonOK"]["GetChecked"]();
In keyword tests, you can use the On-Screen Action operation to call an object’s native method. For more information, see Calling Object Methods.
Data Type Casting
Sometimes, debug information is generated incorrectly, which causes errors when calling methods from scripts, for example:
- Some methods can have parameters that are pointers to one- or two-byte values (short int *, wchar_t * or bool * in C++). Debug information treats these parameters as a pointer to a string, so when calling a method from script, TestComplete attempts to pass a string to the parameter and the method call will fail. To avoid the problem, use the DebugAgent.TreatPCharAsVType method before calling your application’s method.
- Some methods may return pointers to objects or interfaces (for instance, to the IDispatch interface or to a TForm object). In certain cases, TestComplete cannot determine the resulting type of a method and that may cause an error when you call the method from script. To avoid the problem, use the DebugAgent.TreatResultPointersAs method.
- Methods can use various calling conventions (stdcall, safecall and so on). Sometimes, debug information reports that a method uses the stdcall convention while it is the safecall convention that the method actually uses. Calling such methods from script will cause an error. To avoid the problem, you can use the DebugAgent.TreatStdCallAsSafeCall method.
For a detailed description of how to resolve possible type collisions, see Calling Methods and Properties of Open Applications’ Objects.
Important Notes
-
In the Object Spy or Object Browser, native properties and methods of C++Builder objects are displayed only in the Advanced view mode.
-
TestComplete provides access to native object properties, fields and methods of any access type - public, protected, private and published.
However, private and protected properties are not displayed by default, because a property’s get accessor defined by the application developer may perform unsafe operations in the application. If you need to view private and protected properties, enable the Show hidden properties option in the TestComplete Options dialog.
-
If a native property (or method) has the same name as a test object property (method) provided by TestComplete, the native property (method) can be accessed via the
NativeDelphiObject
property. For example, you can access the nativeName
property of a C++Builder application’s form as follows:JavaScript, JScript
Aliases.Orders.MainForm.NativeDelphiObject.Name
Python
Aliases.Orders.MainForm.NativeDelphiObject.Name
VBScript
Aliases.Orders.MainForm.NativeDelphiObject.Name
DelphiScript
Aliases.Orders.MainForm.NativeDelphiObject.Name
C++Script, C#Script
Aliases["Orders"]["MainForm"]["NativeDelphiObject"]["Name"]
-
The leading underscore ( _ ) in property and method names is replaced with the character z. For example, a property named
_flag
is accessible aszflag
, a method named__reset()
is accessible asz_reset()
, and so on. -
If the object contains overloaded methods (methods with the same name but different parameters and return value types), TestComplete appends indexes to method names in order to distinguish among them. For example,
GetChildAtPoint()
andGetChildAtPoint_2()
. To determine which index-suffixed method name corresponds to which overloaded method, examine the method’s parameter list in the Object Spy, Object Browser or Code Completion. -
Some native properties and methods of C++Builder objects are unavailable to TestComplete. For more information, see Object Properties, Fields and Methods That Are Unavailable to TestComplete.
See Also
Testing C++Builder Applications
Testing C++Builder Applications - Overview