TestFx - How to test validation dialogs with no ids

最后都变了- 提交于 2019-12-06 06:16:44

This is an example for Alert based dialog:

In your test:

alert_dialog_has_header_and_content(
    "Removing 'Almaty' location", "Are you sure to remove this record?");

In you helper test class:

public void alert_dialog_has_header_and_content(final String expectedHeader, final String expectedContent) {
    final javafx.stage.Stage actualAlertDialog = getTopModalStage();
    assertNotNull(actualAlertDialog);

    final DialogPane dialogPane = (DialogPane) actualAlertDialog.getScene().getRoot();
    assertEquals(expectedHeader, dialogPane.getHeaderText());
    assertEquals(expectedContent, dialogPane.getContentText());
}

private javafx.stage.Stage getTopModalStage() {
    // Get a list of windows but ordered from top[0] to bottom[n] ones.
    // It is needed to get the first found modal window.
    final List<Window> allWindows = new ArrayList<>(robot.robotContext().getWindowFinder().listWindows());
    Collections.reverse(allWindows);

    return (javafx.stage.Stage) allWindows
            .stream()
            .filter(window -> window instanceof javafx.stage.Stage)
            .filter(window -> ((javafx.stage.Stage) window).getModality() == Modality.APPLICATION_MODAL)
            .findFirst()
            .orElse(null);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!