gpt4 book ai didi

java - 测试在 TestFX 上通过,但在 headless 模式下未通过

转载 作者:行者123 更新时间:2023-11-30 02:11:19 24 4
gpt4 key购买 nike

我正在使用 TestFX 测试使用 Ctrl 键在 ListView 中选择多个项目,然后单击一个按钮,这会生成一个警报对话框,其内容基于选定的项目。

press(KeyCode.CONTROL);
clickOn((Node) lookup(hasText("Item 0")).query());
verifyThat((Node) lookup(hasText("Item 0")).query(), Node::isFocused);
clickOn((Node) lookup(hasText("Item 1")).query());
verifyThat((Node) lookup(hasText("Item 1")).query(), Node::isFocused);
clickOn((Node) lookup(hasText("Item 2")).query());
verifyThat((Node) lookup(hasText("Item 2")).query(), Node::isFocused);
release(KeyCode.CONTROL);

clickOn("actionButton");
alertDialogHasHeaderAndContent("Items selected: 3"); // my own function

处于头脑清醒模式

测试全部通过。

在 headless 模式

三个 verifyThat 测试全部通过,但是当它单击按钮并验证生成的警报对话框是否正确时,却没有通过;生成的警报就好像只选择了列表中的一项。

结果是:

org.junit.ComparisonFailure: 
Expected :Items selected: 3
Actual :Items selected: 1
<小时/>

为了完整性,这里是alertDialogHasHeaderAndContent:

/**
* Checks the current alert dialog displayed (on the top of the window stack) has the expected contents.
*
* From https://stackoverflow.com/a/48654878/8355496
* Licenced under cc by-sa 3.0 with attribution required https://creativecommons.org/licenses/by-sa/3.0/
* @param expectedHeader Expected header of the dialog
* @param expectedContent Expected content of the dialog
*/
private void alertDialogHasHeaderAndContent(final String expectedHeader, final String expectedContent) {
final Stage actualAlertDialog = getTopModalStage();
assertNotNull(actualAlertDialog);

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

/**
* Get the top modal window.
*
* Adapted from https://stackoverflow.com/a/48654878/8355496
* Licenced under cc by-sa 3.0 with attribution required https://creativecommons.org/licenses/by-sa/3.0/
* @return the top modal window
*/
private 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<>(new FxRobot().robotContext().getWindowFinder().listWindows());
Collections.reverse(allWindows);

return (Stage) allWindows
.stream()
.filter(window -> window instanceof Stage)
.findFirst()
.orElse(null);
}

最佳答案

这是 Monocole 的问题。请参阅https://github.com/TestFX/TestFX/issues/566了解更多信息。

关于java - 测试在 TestFX 上通过,但在 headless 模式下未通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49992629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com