Testing JRubyFX Applications with Automaton

Sep 5, 2015

Just in case you aren’t familiar with JRubyFX, checkout our introduction to JRubyFX.

Automated testing is a must. Automated testing with JRubyFX was a little difficult to get going, but now we have an ever increasing number of integration tests and things have been VERY stable for some time now. At this point, I’m comfortable sharing what we have and confident that others can reproduce this.


Automaton is a GUI testing framework for Swing and JavaFX applications. I chose automaton because… well I got it to work with little effort. I just downloaded their “fat jar” and required it and we were up and running. Automaton does not appear to be the most popular testing framework, so in the future we may migrate to something like testfx or jemmy. But for now, it works for us.


Automaton takes over your mouse and keyboard to perform actions as if a user were doing the same. This is different than your typical selenium tests that “click” or “type” without taking control of the keyboard mouse. This was a little annoying before we moved to Docker as we had to “watch” our tests every time they ran locally. If you fight Automaton, it will just keep on trying to move the mouse until you stop messing with it. We also have a post about our migration to Docker.


Some code was omitted for brevity, but this should get you started:

  1. Instantiate your application just as you would when running the application.
  2. Pass it to FXApp.start_app(app)
  3. Return the “thing” that will control your UI FXer.get_user_with(FXApp.scene.root)

This gives you an FXer which has an API similar to selenium and other web-related test frameworks. This includes retrieving elements in the UI and interacting with them. The test attempts to:

  1. Get the ListView element that holds the information for Brakeman warnings.
  2. Get the number of elements visible in the table.
  3. Click on the search box using the elements ID (just like document selectors, # represents the ID).
  4. Type a few letters and hits the enter key.
  5. Give the UI some time to update (in fact, waaaaay too much time)
  6. Count the number of elements and verify that the search terms caused the number of visible warnings to decrease by any amount.
  7. Clears the search by clicking on a button element.
  8. Verify that all of the hidden items become visible.
  9. Exits. JRubyFX::Application::Platform.exit is required else your test will hang indefinitely.