AWTObject Method

Applies to TestComplete 15.62, last modified on March 19, 2024

Description

Use this method to obtain a scripting interface to the specified object of a Java application that was created with AWT classes. The resulting object contains both methods and properties defined in application code as well as methods, properties and actions provided by TestComplete.

Declaration

TestObj.AWTObject(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.AWTObject(ClassName, AccName)

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    
AccName [in]    Required    String    
Result Object

TestObj.AWTObject(ClassName, AccName, Index, WndIndex)

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    
AccName [in]    Required    String    
Index [in]    Required    Integer    
WndIndex [in]    Optional    Integer Default value: -1   
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 name of the desired object as it is specified in the tested application’s source code (the string that is returned by object’s getName method).

ClassName

The window’s class name is specified by the application’s code (not the operating system’s class name). Note that you should specify the short class name, for instance, JRootPane, rather than javax.swing.JRootPane. You can use wildcards (* and ?) in this parameter.

AccName

Accessible window caption (the value returned by the javax.accessibility.AccessibleContext.getAccessibleName() method). You can use wildcards (* and ?) in this parameter.

Index

Index of the window among other windows belonging to the same parent object (TestObj). This index is zero-based.

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 0, the second -  1 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.

WndIndex

The window index of an AWT application’s object. This parameter is used if the parent object contains several child objects that have the same class name, accessible name and index. The parameter value coincides with the value of the Index property. This only happens if the following conditions are met:

  • The addressed component is a windowed component.

-- and --

  • One of the following conditions are met:
    • The addressed component has a parent Java component (not parent window, but the parent component in Java terms, that is, the object that is returned by the component’s getParent() method).
        -- and --
      This parent component is not a windowed control (for instance, Box).

    -- or --

    • The addressed component is a top-level window.
        -- and --
      It that has a parent Java component.
        -- and --
      This parent component is a windowed component.

    -- or --

    • The addressed component does not have a parent component in Java terms.

For more information, see Addressing Objects in Java Applications.

Result Value

The AWTObject method returns an object that provides a scripting interface to an object located in a Java AWT application. If TestComplete cannot access the specified object (for example, this object does not exist), the method will return an empty stub object and post an error message to the test log. To determine whether AWTObject returns a valid object, use the Exists property of the resultant object. If this property returns False, then the returned object is a stub object and the call to AWTObject was not successful.

Remarks

The returned object contains both 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 or properties having the same name. When 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 NativeJavaObject namespace.

The AWTObject method is available only if the Java Application Support plugin is installed. 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 Java AWT application, you should use the AWTObject instead.

To obtain the class name, accessible name and index used by the second or third implementation of the AWTObject method, use the JavaClassName, AWTComponentAccessibleName and AWTComponentIndex properties. To obtain the window index, use the Index property.

See Also

SwingObject Method
Addressing Objects in Java Applications
Object Browser Naming Notation
Using Namespaces
About Open Applications
JavaClassName Property
AWTComponentAccessibleName Property
AWTComponentIndex Property
Index Property (Window and BrowserWindow Objects)
Index Property (Process and Browser Objects)
WaitAWTObject Method
Window Method
WaitWindow Method

Highlight search results