I have a question about testFx 4. There is a GUI object, where I want to set text into TextField ("#searchField").
It's works in TestFx 3 as follows:
//Load FXML
@Override
protected Parent getRootNode() {
Parent parent = null;
try {
FXMLLoader loader = new FXMLLoader();
loader.setResources(ResourceBundle.getBundle(ENTITIES_FIELDS_BUNDLE_PATH, Locale.GERMANY));
parent = loader.load(this.getClass().getClassLoader().getResource(SHOW_ALL_LAYOUT_PATH).openStream());
} catch (IOException ex) {}
return parent;
}
//Set text into Field and check it's there
@Test
public void setBothnamesAndCheckEnabledSearchButton() {
TextField searchField = find("#searchField");
searchField.setText("new text");
verifyThat("#searchField", hasText("new text"));
}
So, it works and everything fine.
100% same case in TestFx 4:
@Override
public void start(Stage stage) throws Exception {
try {
FXMLLoader loader = new FXMLLoader();
loader.setResources(ResourceBundle.getBundle(ENTITIES_FIELDS_BUNDLE_PATH, Locale.GERMANY));
AnchorPane pane = (AnchorPane)loader.load(this.getClass().getClassLoader().getResource(SHOW_ALL_LAYOUT_PATH).openStream());
Scene scene = new Scene(pane);
stage.setScene(scene);
} catch (IOException ex) {}
}
@Test
public void setBothnamesAndCheckEnabledSearchButton() {
clickOn("#searchField").write("new text");
verifyThat("#searchField", hasText("new text"));
}
I become always "FxRobotException: the query "#searchField" returned no nodes. So he doesn't "see" the same TextField...
What am I doung wrong? I'm sure it's something really stupid I can't see... Can anybody please help me? Thanks!
So I finally found an answer: i schould call
stage.show()
at the end of overridenstart()
method. testFX doesn't find any invisible components...