Testing JavaFX UIs - Part 3 of ?: Node-based Robot and Fixtures (with Demo)

DZone 's Guide to

Testing JavaFX UIs - Part 3 of ?: Node-based Robot and Fixtures (with Demo)

· Java Zone ·
Free Resource

After I learned how to launch a compiled JavaFX UI and a little bit about JavaFX's node hierarchy, I thought I had enough information to start working a JavaFX-specific node-based Robot and fixtures (similar to the ones in FEST-Swing.)

I did little bit of progress this past weekend. Please note that I'm working with JavaFX's "desktop profile" only (at least for now.)

The following are some of the classes I added to the project:

  • JavaFXRobot: simulates a user clicking on a JavaFX node.
  • NodeFinder: knows how to find nodes in a hierarchy given some search criteria.
  • NodeMatcher: provides the search criteria to NodeFinder.
  • SwingButtonNodeMatcher: matches nodes that have a JButton attached to them. Matching can be done by type, node id, or button text.
  • TextBoxMatcher: matches nodes that have a JavaFX text box attached to them. Matching can be done by type or node id.
  • FrameFixture: knows how to look up nodes in a JavaFX UI.
  • SwingButtonFixture: simulates user input on and verifies state of a Swing button.
  • TextBoxFixture: verifies state of a JavaFX text box.


In a previous post, I wrote a pretty long (and hacky) functional test for Jim Weaver's calculator demo (you can find the test here.) It took more than 90 lines just to verify that the calculator's text box is updated correctly when the user clicks on a button (!)

With the new JavaFxRobot and node fixtures, the test is reduced to the following:

@Test public class CalculatorTest {
private JavaFxRobot robot;
private FrameFixture calculator;

@BeforeMethod public void setUp() {
robot = BasicJavaFxRobot.robotWithNewAwtHierarchy();
JFrame calculatorFrame = launch(Calculator.class);
calculator = new FrameFixture(robot, calculatorFrame);

@AfterMethod public void tearDown() {

public void shouldUpdateTextBoxWithPressedNumber() {


Please click the image to see the test running: (QuickTime format)


The node-based fixtures are very similar to the ones in FEST-Swing. The following code listing, using the calculator example, shows some of the ways to look up a node that contains an attached JButton:

calculator.swingButton();  // any node that has a JButton
calculator.swingButton("button7"); // by node id
calculator.swingButton(withText("7")); // by button text
calculator.swingButton(withId("button7").andText("7")); // by node id *and* button text


The FEST-JavaFX project is in its very early stages. There is a lot to learn and a lot of work to do. A good starting point would be to finish support for Swing components in JavaFX UIs, since we can apply the lessons we learned while working on FEST-Swing.

I checked-in the code into the project FEST-JavaFX, which is licensed under GPL v2 (with classpath exception,) until we figure out the best license to use (without violating any of the dependencies' licenses, etc.)

Future posts will include how to set up Maven and Eclipse projects that mix Java and JavaFX code (hopefully this week.)

Feedback is always appreciated

From http://www.jroller.com/alexRuiz


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}