0

I am using junit5 Testfx with jdk 11. I have the following test

@Test
    void should_contain_button_with_text(FxRobot robot) {
            robot.clickOn("#newCol").write("Done");
            robot.press(KeyCode.ENTER);
            robot.clickOn("#newCard").write("Cleaning");
            press(KeyCode.ENTER);
            robot.sleep(2000);
    }

Both newCol and newCard are textfields.

Expected result should be the robot first goes to the newCol and after pressing enter it should go to newCard and do the same.

However, it goes to newCol and presses enter fine but on the second press it does not work. Why is this the case. Can the press(KeyCode) only be pressed once?

If someone can please help me out I would really appreciate it.

  • Maybe you have to simulate releasing the enter key before it can be pressed again? – Slaw Dec 14 '19 at 15:10
  • @Slaw thanks alot, I never knew we had to release them after. It did the trick ;) –  Dec 14 '19 at 15:13
  • 1
    I can't find decent documentation about this. The [wiki](https://github.com/TestFX/TestFX/wiki/Robots-and-Queries) simply does not have anything related to key events, as far as I can tell. The best I could find is the documentation of [`KeyboardRobot#press(KeyCode...)`](http://testfx.github.io/TestFX/docs/javadoc/testfx-core/javadoc/org.testfx/org/testfx/robot/KeyboardRobot.html#press(javafx.scene.input.KeyCode...)), which only says: "_Presses the given keys, until explicitly released via `release(KeyCode...)`. Once pressed, `WaitForAsyncUtils.waitForFxEvents()` is called_". – Slaw Dec 14 '19 at 15:26

1 Answers1

1

as @Slaw suggested, you first have to release the key in order to use it again.

 robot.press(KeyCode.ENTER).release(KeyCode.ENTER);

The above did the trick. Same goes for any other key actions.