Identifying Java Objects

Applies to TestLeft 15.40, last modified on March 17, 2022
Search Patterns

TestLeft allows you to test Java AWT, Swing, and SWT applications. To search for objects in Java AWT/Swing applications, you use search patterns of the AWTPattern type.

.NET: The pattern belongs to the SmartBear.TestLeft.TestObjects.Swing namespace.

Java: The pattern belongs to the com.smartbear.testleft.testobjects package.

This pattern uses the following properties:

Property Type Description
AWTComponentAccessibleName String The object’s accessible name. This is the value returned by the javax.accessibility.AccessibleContext.getAccessibleName() method.
AWTComponentIndex Integer The object’s index (0-based) among sibling objects of the same class.
AWTComponentName Name The object name specified by the developers in the application code. This is the value returned by the object’s getName() method.
Enabled Boolean Specifies whether the object is enabled or disabled. Disabled objects are usually shown grayed out.
Index Integer Used for windowed objects. The object’s position in the front-to-back order (Z-order) within the parent object. Indexes start from 1 and are unique among sibling objects with the same window class (the WndClass property value). You can see this value in the TestLeft UI Spy.
JavaFullClassName String The object’s class name including the package name. For example, javax.swing.JCheckBox.
Visible Boolean Specifies whether the object is visible in the application. Objects that are out of screen bounds or overlapped by other objects are still considered visible.

Similarly, to search for SWT objects, you use SWTPattern pattern.

.NET: The pattern belongs to the SmartBear.TestLeft.TestObjects.SWT namespace.

Java: The pattern belongs to the com.smartbear.testleft.testobjects package.

This search pattern uses the following properties:

Property Type Description
Enabled Boolean Specifies whether the object is enabled or disabled. Disabled objects are usually shown grayed out.
Index Integer Used for windowed objects. The object’s position in the front-to-back order (Z-order) within the parent object. Indexes start from 1 and are unique among sibling objects with the same window class (the WndClass property value). You can see this value in the TestLeft UI Spy.
JavaFullClassName String The object’s class name including the package name. For example, org.eclipse.swt.widgets.ToolBar.
Visible Boolean Specifies whether the object is visible in the application. Objects that are out of screen bounds or overlapped by other objects are still considered visible.
WndCaption String The object text. For example, window title, button text, text in a text box, check box caption, and so on.
Example

C#

ITopLevelWindow frame = Driver.Find<IProcess>(new ProcessPattern()
{
    ProcessName = "javaw"
}).Find<ITopLevelWindow>(new AWTPattern()
{
    JavaFullClassName = "javax.swing.JFrame",
    AWTComponentAccessibleName = "SwingSet2"
});

Visual Basic .NET

Dim frame As ITopLevelWindow = Driver.Find(Of IProcess)(New ProcessPattern() With {
   .ProcessName = "javaw"
}).Find(Of ITopLevelWindow)(New AWTPattern() With {
   .JavaFullClassName = "javax.swing.JFrame",
   .AWTComponentAccessibleName = "SwingSet2"
})

Java

TopLevelWindow frame = driver.find(TestProcess.class, new ProcessPattern() {{
   ProcessName = "javaw";
}}).find(TopLevelWindow.class, new AWTPattern() {{
   JavaFullClassName = "javax.swing.JFrame";
   AWTComponentAccessibleName = "SwingSet2";
}});

Custom Properties

You can also specify custom properties by using the .add("propertyname", value) method of the pattern object. See Using Custom Properties in Search Patterns.

See Also

Understanding Object Identification
Preparing Java and JavaFX Applications for Testing

Highlight search results