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
2
votes
1 answer

TestFX - Testing if a scene opens when a button's clicked (JavaFX - IntelliJ)

I'm trying to test a Java FX application within IntelliJ and I'm using TestFX however I'm unsure how to test whether a window opens when a button on the interface is clicked. I've tried making a getter to get the primary stage, then assertingTrue…
Harry
  • 21
  • 3
2
votes
2 answers

TestFx - How to test javaFx MenuItems

Since MenuItem is not a Node, I'm not able to look it up. How do I test, if some MenuItem is disabled? I've tried to look it up as it was a node and it returned me something, which looks like this.. (toString representation of returned…
Mono
  • 206
  • 1
  • 21
2
votes
1 answer

How can I run testfx tests in series?

I've got 2 testfx tests which each run successfully but when run in series, fail. The error message is: --- Exception in Async Thread --- java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Cannot set style once stage has been…
Return_Of_The_Archons
  • 1,731
  • 3
  • 20
  • 26
2
votes
1 answer

TestFX clicking menu items

I'm writing a JavaFX application with a menubar. I have given the menu items CSS ids, and I want to use TestFX to click on them. Here's the code: clickOn("#menu-file").clickOn("#menu-file-new-project"); When I run this I can see my mouse move to…
Nick
  • 6,900
  • 5
  • 45
  • 66
2
votes
2 answers

How to wait until element is visible using TestFX?

I'm trying to use waitUntil() method from TestFX to wait until a dialog appears on the screen. I found the example provided by the Wiki, but it doesn't seem to work with me. Can anyone help me to figure this out?
2
votes
1 answer

JavaFX, Is there any callback for Platform.runlater()?

My application adds multiple Runnable on FX thread, by calling Platform.runlater method, then, I want to do some calculations only when there is no additional Runnable is in the FX Platform queue. But I don't know the right way, is there any event…
Reza Afzalan
  • 5,646
  • 3
  • 26
  • 44
1
vote
0 answers

How do I install TestFX in a maven project?

org.openjfx javafx-media 15 org.openjfx
1
vote
1 answer

TestFX with JUnit4: How can I press the ENTER key in a certain TextField?

I want to test, if a certain TextField (maybe there are several TextFields) has an EventHandler set via setOnAction. In the test code I can set the content (e.g. "HelloWorld") into the TextField. In my understanding I have to place the curser at the…
wnck
  • 11
  • 3
1
vote
0 answers

JavaFX GUI testing with TestFX fails on Github workflow but not on local computer

As per title, I am using TestFX to run some simple test on the GUI of a JavaFX application. The result whenever I run gradle test, will return 340 tests passed out of 340 tests. However, on Github's workflow checks for pull requests, it says 340…
Ken Gondor
  • 115
  • 2
  • 9
1
vote
1 answer

TestFX doesn't work when testing setOnKeyPressed on a Pane

I have a problem while testing a JavaFX application with TestFx. I put a sample, using just a VBox instead of a BorderPane that i use in real application. I just fill the pane with a canvas, to not have it empty, but with or without nothing…
katamar
  • 31
  • 3
1
vote
1 answer

How to use TestFX to test a scene's contents using JavaFXML

I'm wondering how I'm supposed to be testing contents of certain scenes in JavaFXML when using TestFX. Examples include these…
ancd3ea4
  • 195
  • 1
  • 1
  • 14
1
vote
1 answer

JavaFX: Populating mock list view causes null pointer exception during Maven test build

The method lvSelected.setItems(selectedList) causes null pointer exception on following code, but only when I try to use Maven to clean test, and only when using a 32-bit JRE. What could be causing this? When I debug, both the ListView and the…
georgebp
  • 193
  • 3
  • 17
1
vote
1 answer

Why isn't the correct TextField being clicked TestFX?

I have 2 text fields inside a button bar. I have given both a fxid. Both Textfields are next to each other. The left text field has a fx:id newCol While the texfield to it's right has a fx:id of Name I am doing the following test @Test public…
user12150819
1
vote
1 answer

TestFx - Method Start is not called when extending ApplicationTest

I was updating my application from JDK 8 to 13 and to Javafx 13. Updated all dependencies to the latest updated ones. But now one of my tests returns error. The public void start(Stage stage) is not called on initialization, but on After the…
1
vote
1 answer

Mocking an FileChooser in TestFx using mockito

I tried to test if a file is chosen in the inside an FileChooser and written as String into an TextField. I am using: testfx 4.0.4-alpha mockito 2.1.0 I found this on the web: https://gitter.im/TestFX/TestFX/archives/2017/10/05 Mocking the…
Zubty
  • 369
  • 2
  • 18