Description
Use this method to obtain a scripting interface to the specified window or control of a .NET application created with Microsoft Windows Forms library. The resulting object contains methods and properties defined in the application code as well as methods, properties and actions provided by TestComplete.
Declaration
TestObj.WinFormsObject(Name)
TestObj | A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section | |||
Name | [in] | Required | String | |
Result | Object |
TestObj.WinFormsObject(ClassName, WndCaption)
TestObj | A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section | |||
ClassName | [in] | Required | String | |
WndCaption | [in] | Required | String | |
Result | Object |
TestObj.WinFormsObject(ClassName, WndCaption, Index)
TestObj | A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section | |||
ClassName | [in] | Required | String | |
WndCaption | [in] | Required | String | |
Index | [in] | Required | Integer | |
Result | Object |
Applies To
The method is applied to the following objects:
View Mode
To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.
Parameters
The method has the following parameters:
Name
The object name as it is specified by the developers in the application’s source code. This is the value of the object’s WinFormsControlName
property.
Note that .NET compilers do not include object names in the executable if developers do not assign a value to the object’s Name
property in the code. In this case, use the second implementation of the method to address the desired object.
ClassName
The object’s class name as it is specified in the application code. This is the same value as the object’s ClrClassName
property. Note, that you should specify a short name rather than the full class name, for instance, Button
rather than System.Windows.Forms.Button
. You can use wildcards (* and ?) in this parameter.
Note that class names of .NET application objects may be unavailable. For instance, this happens if the application was processed with an obfuscator. In this case, TestComplete replaces the class name with an underscore and an index. To determine the class name used, explore the tested application in the Object Browser.
WndCaption
The caption of the desired window or control. The caption can include wildcards (* and ?).
Index
The object’s index, starting from 1, among other objects that belong to the TestObj object and that have the same window class name (the WndClass
property value) and caption.
The Index parameter is used only if an object contains two or more child objects that have the same class name and caption. It is used to distinguish these objects from each other. The first found object has an index of 1, the second - 2 and so on.
If there is only one child object with the specified class name and caption, index should not be specified. To decide whether the index should be used, explore your application in the Object Browser panel and use the naming format that is used by the panel.
Result Value
The WinFormsObject
method returns an object that provides a scripting interface to an object located in a WinForms .NET application (.NET applications are always “open” to TestComplete). If TestComplete cannot access the specified object (for example, this object does not exist), WinFormsObject
will return an empty stub object and post an error message to the test log. To determine whether WinFormsObject
returns a valid object, use the Exists
property of the resultant object. If Exists
returns False, then the returned object is a stub object and the call to WinFormsObject
was not successful.
Remarks
If you use only one parameter, TestComplete considers the use of the first implementation of the WinFormsObject
method and the parameter as the object’s name. If you use two or three parameters, TestComplete considers it as using the second or third implementation correspondingly.
The object returned by the WinFormsObject
method contains methods and properties defined in the application code as well as methods, properties and actions provided by TestComplete. The returned object may hold two or more methods and properties having the same name. If you call such a method or property, a naming conflict will occur. To avoid it and to specify which method or property is to be called, use the NativeClrObject namespace.
The WinFormsObject method is available only if the .NET Application Support plugin is installed and enabled in File | Install Extensions. Otherwise, the method is absent in the method list of the TestObj object.If the plugin is installed, you cannot use the Window method to address windows of your .NET application, you should use WinFormsObject instead. |
Example
For examples of using the WinFormsObject
method, see Addressing Objects in .NET Applications.
See Also
WaitWinFormsObject Method
Testing .NET Applications
Addressing Objects in .NET Applications
VCLNETObject Method (Window Objects)
VCLNETObject Method (Process Objects)