0

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 provide additional info as to why a test failed.

This is a useful pointer... so say I want to say verify that "the JavaFX dialog/window is at least 600 pixels wide and at most 400 pixels high"?

NB for what it's worth I'm using the org.junit approach because the examples on the TestFX github site seem to. Actually I'm a Groovy fan and would hope to switch to the Spock TestFX implementation before too long.

NB2 it occurs to me that one way to get the Stage in testing code is to make the Stage a field of the class under test:

class ClickApplication extends Application {

    Stage allTheWorldsA

    public void start(Stage stage) {
        Parent sceneRoot = new ClickPaneGG()
        Scene scene = new Scene(sceneRoot, 500, 1000)
        stage.setScene(scene)
        stage.show()

        allTheWorldsA = stage
    }

... but somehow this feels the wrong way to do things: if the Stage is passed as a parameter of start it feels like the designers didn't want you to make a class field of it.

mike rodent
  • 14,126
  • 11
  • 103
  • 157
  • 1
    You can get the window of a node by using `node.getScene().getWindow()`. Is that you you're looking for? – Slaw Apr 09 '19 at 07:55
  • 1
    don't quite understand what you are asking: ApplicationTest is-a FXRobot such that you can access the (all) window with `listWindows().get(0)` or `window(int)` and then use `verifyThat(window, myMatcher, myOutputFunction)`. – kleopatra Apr 09 '19 at 10:25
  • Thanks... both of these answers are helpful. – mike rodent Apr 09 '19 at 11:28

0 Answers0