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
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 require
d 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.
Demo
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.
Code
Some code was omitted for brevity, but this should get you started:
- Instantiate your application just as you would when running the application.
- Pass it to
FXApp.start_app(app)
- 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:
- Get the
ListView
element that holds the information for Brakeman warnings. - Get the number of elements visible in the table.
- Click on the search box using the elements ID (just like document selectors,
#
represents the ID). - Type a few letters and hits the enter key.
- Give the UI some time to update (in fact, waaaaay too much time)
- Count the number of elements and verify that the search terms caused the number of visible warnings to decrease by any amount.
- Clears the search by clicking on a
button
element. - Verify that all of the hidden items become visible.
- Exits.
JRubyFX::Application::Platform.exit
is required else your test will hang indefinitely.