我有一个关于testFx 4的问题,有一个GUI对象,我想将文本设置为TextField ("#searchField")。
它在TestFx 3中的工作如下:
//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"));
}所以,它很有效,一切都很好。
TestFx 4中100%的情况相同:
@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"));
}我总是变成"FxRobotException:查询“"#searchField”没有返回任何节点,所以他没有“看到”相同的TextField.
我怎么了doung?我肯定这是件很愚蠢的事我看不见..。有人能帮帮我吗?谢谢!
发布于 2017-02-28 14:58:34
因此,我终于找到了一个答案:我应该在overriden start()方法的末尾调用start()。testFX找不到任何看不见的部件..。
https://stackoverflow.com/questions/41188361
复制相似问题