首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在TestFX 4中实现?

如何在TestFX 4中实现?
EN

Stack Overflow用户
提问于 2016-12-16 16:13:00
回答 1查看 1.3K关注 0票数 0

我有一个关于testFx 4的问题,有一个GUI对象,我想将文本设置为TextField ("#searchField")。

它在TestFx 3中的工作如下:

代码语言:javascript
复制
//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%的情况相同:

代码语言:javascript
复制
@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?我肯定这是件很愚蠢的事我看不见..。有人能帮帮我吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-28 14:58:34

因此,我终于找到了一个答案:我应该在overriden start()方法的末尾调用start()。testFX找不到任何看不见的部件..。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41188361

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档