Identifying JavaFX Objects

Applies to TestLeft 4.72, last modified on December 21, 2020
Search Patterns

To search for objects in JavaFX applications, you use search patterns of the JavaFXPattern type:

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

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

This 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.
JavaFullClassName String The object’s class name including the package name. For example, javafx.scene.control.TableView.
JavaFXObjectIndex Integer The object’s index (0-based) among sibling objects of the same class. Scenes have index 0. You can see this value in the TestLeft UI Spy.
JavaFXObjectName String For Nodes, this is the node ID returned by its getId() method. For Scenes and Stages, this is an empty string.
JavaFXObjectText String The object text or Stage’s title. Scenes have empty text.
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.
Example

C#

IButton button = Driver.Find<IProcess>(new ProcessPattern()
{
   ProcessName = "javaw"
}).Find<ITopLevelWindow>(new JavaFXPattern()
{
   JavaFullClassName = "javafx.stage.Stage",
   JavaFXObjectText = "Table View Sample"
}).Find<IButton>(new JavaFXPattern()
{
   JavaFXObjectName = "buttonAdd"
}, 2);

Visual Basic .NET

Dim button As IButton = Driver.Find(Of IProcess)(New ProcessPattern() With {
   .ProcessName = "javaw"
}).Find(Of ITopLevelWindow)(New JavaFXPattern() With {
   .JavaFullClassName = "javafx.stage.Stage",
   .JavaFXObjectText = "Table View Sample"
}).Find(Of IButton)(New JavaFXPattern() With {
   .JavaFXObjectName = "buttonAdd"
}, 2)

Java

Button button = driver.find(TestProcess.class, new ProcessPattern() {{
   ProcessName = "javaw";
}}).find(TopLevelWindow.class, new JavaFXPattern() {{
   JavaFullClassName = "javafx.stage.Stage";
   JavaFXObjectText = "Table View Sample";
}}).find(Button.class, new JavaFXPattern() {{
   JavaFXObjectName = "buttonAdd";
}}, 2);

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.

Custom JavaFX Objects in the Object Hierarchy

TestLeft can include or omit objects of certain type in the object hierarchy of JavaFX applications. By default, TestLeft includes objects whose class name or the class name or their parent matches the pattern:

  • javafx.scene.SubScene
  • javafx.scene.control.Control
  • javafx.scene.web.WebView
  • com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer

You can configure TestLeft to include the needed objects in the object hierarchy:

C#

Driver.Options.JavaFX.AddJavaFxClass("javafx.scene.canvas.Canvas", true);

Visual Basic .NET

Driver.Options.JavaFX.AddJavaFxClass("javafx.scene.canvas.Canvas", True)

Java

driver.getOptions().getJavaFX().addJavaFxClass("javafx.scene.canvas.Canvas", true);

Note: The changes are effective throughout the test run, until you start the next test run.

You specify the object types you want TestLeft to recognize using their class name. You can use wildcards (* and ?) to match multiple object types based on a common pattern. The asterisk (*) matches a string of any length, including an empty string, the question mark (?) matches any single character or no character.

Recognizing Custom JavaFX Objects at Design Time

Currently, there is no direct way to include custom JavaFX object types in the object hierarchy at design time, but you can use the following workaround:

  1. Create a dummy test that will add needed object types to the list of classes:

    C#

    [TestMethod]
    public void Test()
    {
      // Add your custom object types here
      Driver.Options.JavaFX.AddJavaFxClass("custom_javafx_class1", true);
      Driver.Options.JavaFX.AddJavaFxClass("custom_javafx_class2", false);

    }

    Visual Basic .NET

    <TestMethod()>
    Public Sub Test()
      ' Add your custom object types here
      Driver.Options.JavaFX.AddJavaFxClass("custom_javafx_class1", True)
      Driver.Options.JavaFX.AddJavaFxClass("custom_javafx_class2", False)

    End Sub

    Java

    @Test
    public void Test() throws Exception{
      // Add your custom object types here
      driver.getOptions().getJavaFX().addJavaFxClass("custom_javafx_class1", true);
      driver.getOptions().getJavaFX().addJavaFxClass("custom_javafx_class2", false);

    }

  2. Run the test.

  3. Changes in options will be effective throughout the test run.

  4. After the test run is over, open UI Spy and examine the object tree (refresh the object tree, if needed).

  5. UI Spy will apply the new setting. You will be able to explore your custom objects and generate identification code for them.

Changes in options will remain effective until you start another test.

See Also

Understanding Object Identification
Preparing Java and JavaFX Applications for Testing

Highlight search results