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

Javafx application - Robot action unable to perform on login screen - Stuck at Launch need to move on testcase loginlogout call when calling from main

Javafx application - Robot action unable to perform on login screen - Stuck at Launch need to move on testcase loginlogout call when calling from main. I would like to run login logout testcase on javafx application. I have run the main method. I am…
Nee
  • 11
  • 3
0
votes
1 answer

BoundsLocatorException running testfx in headless mode

I'm running some TestFx test cases that work fine in my local for headless mode and headful mode but for some reason when the same test runs in jenkins in headless mode only I receive the following message on lines where some buttons are…
Ronnie Phelps
  • 83
  • 1
  • 11
0
votes
0 answers

Change speed of TestFX robots?

Specifically the WriteRobot / WriteRobotImpl. It seems to write things rather slowly and I'd like to make it write faster. Edit In response to M.S.'s comment I tried this (NB at this point I hadn't worked out that WriteRobot was involved, not…
mike rodent
  • 14,126
  • 11
  • 103
  • 157
0
votes
1 answer

Why am I obliged to use a GroovyMock in this case?

Here is an MCVE: main.groovy: package core import javafx.application.Application import javafx.stage.Stage import javafx.fxml.FXMLLoader class App extends Application { FXMLLoader fxmlLoader = new FXMLLoader() static App instance …
mike rodent
  • 14,126
  • 11
  • 103
  • 157
0
votes
1 answer

press(KeyCode.Enter) does not work more than once TestFX?

I am using junit5 Testfx with jdk 11. I have the following test @Test void should_contain_button_with_text(FxRobot robot) { robot.clickOn("#newCol").write("Done"); robot.press(KeyCode.ENTER); …
user12150819
0
votes
1 answer

Maven Surefire Plugin is not executing integration tests using TestFX properly

I have an JavaFX Application that uses TestFX as testing framework. Unfortunately, when executing the tests in headless mode (with the options -Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw) via mvn test…
raphaelmue
  • 21
  • 4
0
votes
1 answer

JavaFx MediaPlayer behaves differently in unit test vs application, why?

I want to load meta data from an MP3 file, to be played by a JavaFx MediaPlayer. This works fine in the unit test, but not in the application. In the unit test, 6 items of metaData reported, but zero in the application. The method that "does the…
Helge
  • 145
  • 9
0
votes
2 answers

TestFX Spock Gradle Project Openjdk 11 - Zero Test Results

Why is my Spock test not executed and I get zero test results when I execute: ./gradlew clean test with my TestFX Spock Gradle Project with Openjdk 11? Here's the zero test results: My Spock test class gets compiled OK but not executed. Here's…
David Miller
  • 694
  • 6
  • 7
0
votes
1 answer

Is there a function to test choice box selection in TestFX?

I want to test my written JavaFX GUI with TestFX. In one step there are some ChoiceBoxs that i want to test. I have tried the following code so far: this.step("fill creation view", () -> { this.clickOn("#receiverChoiceBox").clickOn("Max…
Lars
  • 173
  • 5
  • 18
0
votes
0 answers

How do I refer to the top Node in TestFX?

Just getting started with TestFX and I'm wondering how to refer to the top Node (i.e. the Stage). Here I see it says All TestFX tests should use verifyThat(Node, Matcher, Function) when writing tests, so that the developer can use DebugUtils to…
mike rodent
  • 14,126
  • 11
  • 103
  • 157
0
votes
1 answer

How to launch application after each test Junit5 TestFX

I'm writing an application test with Junit5 and TestFX. My intention is that the main test class relaunches the application after each test. As far as I know, I shall use the annotation @BeforeEach, and it didn't work for me. Here is my test…
Luky
  • 49
  • 1
  • 10
0
votes
1 answer

TestFX clickOn() on particular text on combobox/choicebox

I‘m new to TestFX GUI-testing with fxrobot (javafx). My current task is about clicking on a choice on a drop down menu created with combobox. I didn‘t find any tutorials mentioning this issue. Is it really possible to implement the clickOn() method…
Luky
  • 49
  • 1
  • 10
0
votes
1 answer

Using TestFX with Cucumber

I'm trying to use Cucumber with TestFX but cant get any nodes from the application. I've another class of TestFX that works fine and another class of Cucumber which also works fine. But I'm…
Jeredriq Demas
  • 616
  • 1
  • 9
  • 36
0
votes
1 answer

Accessing a TableRow's style data in a TableView

I'm trying to write some TestFX code that will loop through a TableView component and check the background colour for each row is set correctly. What I can't work out is how to actually construct the loop to go through the TableRows as opposed to…
0
votes
0 answers

Native Library D:\jdk 1.8.0 181\jre1.8.0_181\bin\glass.dll already loaded in another classloader

My problem is when I use Powermock with ApplicationTest or GuiTest. I gives Native Library D:\jdk 1.8.0 181\jre1.8.0_181\bin\glass.dll already loaded in another classloader. So I have to show stage without using ApplicationTest or GuiTest. Or is…