Accessing Native Methods of JavaFX Objects

Applies to TestComplete 15.69, last modified on November 13, 2024

TestComplete provides you with access to individual objects of JavaFX applications and to their internal methods. The following sections describe how you can access these native methods from your tests:

About Accessing Native Methods

TestComplete identifies individual GUI objects in JavaFX applications and provides special methods and properties for automating various operations over these objects, getting object data, checking an object's state and so on. However, if these predefined properties and methods are insufficient for your testing needs, you can use native methods of JavaFX objects to complete the desired tasks. These are the same methods that are available for use in the tested application’s source code, as well as custom methods implemented by the application developers. This way, you can perform almost any operation in the tested JavaFX application, even those that cannot be performed via the application’s GUI.

The Object Browser marks objects of JavaFX applications with the glyph. To view native members available for a JavaFX object, use the Object Spy or Object Browser in the Advanced view mode. Note that TestComplete gives access to private, protected and public methods of JavaFX applications’ objects. In the Object Browser, native methods of JavaFX objects are displayed under the Java category (see Important Notes for details):

Native Methods of a JavaFX CheckBox Object in Object Browser

Click the image to enlarge it.

For more information on how to refer to objects in JavaFX applications, see Addressing Objects in JavaFX Applications.

Calling Native Object Methods

When testing a JavaFX application, you can call its object methods from your tests.

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, in script code you can call the native requestFocus method of a JavaFX button as follows:

JavaScript, JScript

Aliases.Java.stage.scene.button.requestFocus();

Python

Aliases.Java.stage.scene.button.requestFocus();

VBScript

Aliases.Java.stage.scene.button.requestFocus

DelphiScript

Aliases.Java.stage.scene.button.requestFocus();

C++Script, C#Script

Aliases["Java"]["stage"]["scene"]["button"]["requestFocus"]();

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.

Invoking a JavaFX object’s native method

Click the image to enlarge it.

Important Notes

  • In the Object Spy or Object Browser, native methods of JavaFX objects are displayed only in the Advanced view mode.

  • If a native method has the same name as the test object method provided by TestComplete, the native method can be accessed via the NativeJavaFXObject property. For example, you can access the native validate method of a JavaFX application’s form as follows:

    JavaScript, JScript

    Aliases.Java.stage.NativeJavaFXObject.validate();

    Python

    Aliases.Java.stage.NativeJavaFXObject.validate();

    VBScript

    Aliases.Java.stage.NativeJavaFXObject.validate

    DelphiScript

    Aliases.Java.stage.NativeJavaFXObject.validate();

    C++Script, C#Script

    Aliases["Java"]["stage"]["NativeJavaFXObject"]["validate"]();

  • If the object contains overloaded methods (methods with the same name but different parameters and they return value types), TestComplete appends indexes to method names in order to distinguish them. For example, GetMousePosition() and GetMousePosition_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.

  • The leading underscore ( _ ) in method names is replaced with the character z. For example, a method named __reset() is accessed as z_reset(), and so on.

See Also

Testing JavaFX Applications

Highlight search results