fujaba / fulibFx

A framework for JavaFX applications that is designed for MVC pattern projects.
https://fujaba.github.io/fulibFx/
MIT License
2 stars 0 forks source link

Nodes are invisible in headless tests for Ludo #72

Open LeStegii opened 8 months ago

LeStegii commented 8 months ago

Describe the bug When testing the Ludo game in headless mode, the tests fail because the bot cannot click on nodes (not visible).

To Reproduce Steps to reproduce the behavior:

  1. Run the tests in headless

Expected behavior The tests shouldn't fail becaues the nodes are visible.

Desktop (please complete the following information):

Additional context The nodes exist and can be used (e.g. using tabs and enter), but they cannot be found when clicked as they are apparently not visible on screen (see #67)

LeStegii commented 6 months ago

When using a real headless enviroment everything seems to work fine. On Windows the node cannot be found and an error is thrown. On MAC, it doesn't throw an error but the node isn't clicked.

Clashsoft commented 6 months ago

Please use this code for testing:


public class BadControllerTest extends ControllerTest {
    @Test
    void bad() {

        try {
            FxAssert.verifyThat("some button that does not exist", Node::isVisible, collectInfos());
        } catch (Exception ex) {
            printInfos();
        }
    }

    public void printInfos() {
        System.err.println(collectInfos().apply(new StringBuilder()));
    }

    public Function<StringBuilder, StringBuilder> collectInfos() {
        final Path dir = Paths.get("build", "failed-test-screenshots");
        try {
            Files.createDirectories(dir);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return DebugUtils.compose(
            DebugUtils.insertHeader("Context:"),
            DebugUtils.showKeysPressedAtTestFailure(this),
            DebugUtils.showMouseButtonsPressedAtTestFailure(this),
            DebugUtils.showFiredEvents(),
            DebugUtils.saveWindow(
                stage,
                () -> dir.resolve(getClass().getSimpleName() + " " + LocalTime.now() + ".png"),
                null));
    }
}