Questions tagged [testfx]

Simple and clean testing for JavaFX.

Simple and clean testing for JavaFX.

Features:

  • A fluent and clean API.
  • Flexible setup and cleanup of JavaFX test fixtures.
  • Simple robots to simulate user interactions.
  • Rich collection of matchers to verify expected states.

Support for:

  • Java 8 features and JavaFX 8 controls.
  • JUnit testing framework and Hamcrest matchers.
  • Precise screenshots of failed tests.
  • Headless testing using Monocle.

Sample:

 public class DesktopPaneTest extends ApplicationTest {
    @Override
    public void start(Stage stage) {
        Scene scene = new Scene(new DesktopPane(), 800, 600);
        stage.setScene(scene);
        stage.show();
    }

    @Test
    public void should_drag_file_into_trashcan() {
        // given:
        rightClickOn("#desktop").moveTo("New").clickOn("Text Document");
        write("myTextfile.txt").push(ENTER);

        // when:
        drag(".file").dropTo("#trash-can");

        // then:
        verifyThat("#desktop", hasChildren(0, ".file"));
    }
 }

As you can see above, TestFX is emulating GUI action with simple methods like drag(String) or write(String). You are able to call the JavaFX-Components directly via the CSS-ID or CSS-Class string. To call the id you have to add a # before the id, to reach the class you need a . before the classname.

Links:

108 questions
12
votes
3 answers

Headless testing with JavaFx and TestFx

I have a simple JavaFx application (Java 8) that has a unit test using TestFx. However, when the test is run, the application window starts up and the mouse is moved to do whatever action is in my test. Can these tests be run in a way where the…
yellavon
  • 2,821
  • 12
  • 52
  • 66
8
votes
1 answer

Record UI elements for TestFX

There is an existing JavaFX based application, which I should write automated tests for. I just started to use TestFX(version 4.0.13-alpha) and looking for advice, how to record and identify UI objects of application. I tried following code to…
plaidshirt
  • 5,189
  • 19
  • 91
  • 181
7
votes
2 answers

Simple TestFX example fails

Working with TestFX 4.0.14 in Eclipse photon and fx9 or fx11 (doesn't matter), the simple example test from the TestFX wiki fails in should_click_on_button() with Expected: Labeled has text "clicked!" but: was "click me!" When looking at…
kleopatra
  • 51,061
  • 28
  • 99
  • 211
6
votes
2 answers

How to test JavaFX (MVC) Controller Logic?

How do we properly write unit/integration tests for the JavaFX Controller logic? Assuming the Controller class I'm testing is named LoadController, and it's unit test class is LoadControllerTest, my confusion stems from: If the LoadControllerTest…
Casey B.
  • 279
  • 3
  • 13
6
votes
2 answers

How to set 'headless' property in a Spring Boot test?

I am testing using Spring Boot with JavaFX (Based on some excellent YouTube videos that explain this). To make it work with TestFX, I need to create the context like this: @Override public void init() throws Exception { SpringApplicationBuilder…
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
5
votes
1 answer

How to avoid HeadlessException when running TestFX on Jenkins?

I am writing a TestFX test case to cover a Java desktop application. One of the interactions calls showDocument() to display an html document using the browser. When running the test locally using Gradle, my test works correctly. But when I run it…
PySerial Killer
  • 428
  • 1
  • 9
  • 26
5
votes
0 answers

TestFX in headless mode on Windows

I have a JavaFx application and I try to run a TestFX junit in headless mode. (in normal mode is working). In Gradle I configured the openjfx-monocle: compile group: 'org.testfx', name: 'openjfx-monocle', version: '8u76-b04' As arguments when I…
Trica
  • 53
  • 6
5
votes
2 answers

Getting started with TestFx

I'm having some trouble getting TestFx working with Oracle's JavaFx HelloWorld app: public class HelloWorld extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage…
yellavon
  • 2,821
  • 12
  • 52
  • 66
5
votes
2 answers

How to unit test that a JavaFX application launches

I've got a JavaFX application, and I want to test if it launches or not. How would I go about doing that? Is it possible with just JUnit, or can TestFX help me in that? My main issue is: How do I shut down the application right after it has…
skiwi
  • 66,971
  • 31
  • 131
  • 216
3
votes
0 answers

Is TestFX compatible with Java 13?

I'm currently using OpenJDK 13, JavaFx 14e-ea+2, testfx-junit 4.0.16-alpha and testfx-core 4.0.15-alpha I updated both from 8 and now the testfx tests are giving errors. The errors are: java.lang.NoSuchMethodError:…
3
votes
0 answers

How to get testfx to find the root's fx:id in testing (the root is a custom control)

I know the way I'm loading my app is probably weird but I don't understand why the testfx suite returns an EmptyNodeQueryException for the root pane org.testfx.service.query.EmptyNodeQueryException: there is no node in the scene-graph matching the…
3
votes
1 answer

enable screenshots feature of failed tests in testfx

I'm currently building tests for a JavaFX app with TestFX with it's following versions : testfx-core 4.0.1-alpha testfx-junit 4.0.1-alpha There is not much information about how to enable screeshot taking feature for failed tests and in case it is…
Hassam Abdelillah
  • 2,246
  • 3
  • 16
  • 37
3
votes
0 answers

How to run TestFX in headless mode?

I'm working on a JavaFX (using TornadoFX) project and I'd like to test it in a headless environment (Circle CI). I've tried what's written here but it does not work. No matter how I configure TextFX I always get the Graphics Device initialization…
Adam Arold
  • 29,285
  • 22
  • 112
  • 207
3
votes
2 answers

TestFx - How to test validation dialogs with no ids

I have an application with grid of records and button insert. After clicking insert, there is a form, where you fill in data and click Ok for adding new record to the grid. After clicking Ok, there is validation which fires dialog with error…
Mono
  • 206
  • 1
  • 21
3
votes
1 answer

TestFx - Can't access login dialog

I have a simple javafx application, where, right after stage.show(), I'm calling login dialog. When I run tests, they does not start to do their work until the login dialog is filled and confirmed manually. For test purposes, I tried to display…
Mono
  • 206
  • 1
  • 21
1
2 3 4 5 6 7 8