KeyCode in the javafx.scene.robot.Robot interface

Mark Raynsford org.openjdk at io7m.com
Sun May 12 10:16:36 UTC 2024


Hello!

I maintain a test harness for JavaFX applications:

https://www.github.com/io7m-com/xoanon

I expose an interface that uses the javafx.scene.robot.Robot
interface internally, but I expose a slightly higher level
API that allows for (amongst other things) typing text as strings
on components rather than sending individual key codes.

The problem I immediately run into is that KeyCodes are keyboard
layout specific, and there doesn't appear to be any way to detect
what keyboard layout is in use. If I, for example, send the KeyCode for
the `@` symbol, I'll actually get `"` on some keyboard layouts. This
can cause some types of tests to fail, even though the code is correct.

Consider a test where an email address is typed into a text field, and
then the form containing the field is checked to see if the text field
accepted/rejected the text as being a valid email address. On some
keyboard layouts, a test that sends the string "someone at example.com"
will fail because what ends up in the text field is actually
"someone"example.com".

I provide a workaround for this: At the start of the test suite run,
xoanon will send every KeyCode to a text field one at a time and see
what character appeared in the text field as a result. It then builds a
mapping between characters to KeyCodes, and it can then do the
translations as necessary when running the rest of the test suite:

https://github.com/io7m-com/xoanon?tab=readme-ov-file#keymap-generation

Unfortunately, this is still rather flaky. This often seems to fail more
or less at random for reasons that aren't clear to me.

Is there some way the Robot interface could be extended to allow for
typing strings? Failing that, is there some way JavaFX could advertise
the underlying keyboard map? I feel like some underlying component must
know the information I'm trying to infer, but it doesn't seem to be
exposed anywhere that I've been able to find.

-- 
Mark Raynsford | https://www.io7m.com


More information about the openjfx-dev mailing list