I'm using Swing to create a GUI for my application that has a JSpinner
named "spinner". Inside the tests, created using AssertJ Swing I have something like this:
import org.assertj.swing.fixture.FrameFixture;
import org.assertj.swing.edt.GuiActionRunner;
FrameFixture window;
MyView view;
GuiActionRunner.execute(() -> {
view = new MyView();
return view;
});
window = new FrameFixture(view);
window.spinner("spinner").enterText("-1");
This code runs without any problems on Ubuntu. However while testing the same code on MacOS with an Italian keyboard, I've noticed that instead of entering "-1" the text written is "'1". This happens also for other symbols like "\\" that turns into an "ù".
If I manually enter "-1" inside the spinner on mac it is written ok. So I guess the problem is associated to enterText()
itself and mac.
Does anyone has an idea of why this is happening? Thanks.
Update:
In order to isolate the problem I've also tried doing:
String minus = java.awt.event.KeyEvent.getKeyText(45);
System.out.println(minus);
From this cheat sheet, I know that 45
key corresponds to -
and indeed this code works correctly.
But then I've tried:
window.spinner("spinner").click();
window.robot().pressAndReleaseKeys(45);
Or similarly by creating a new robot:
robot = new Robot();
robot.setAutoDelay(500);
window.spinner("spinner").click();
robot.keyPress(KeyEvent.VK_MINUS);
This two fragment of code again instead of writing -
write '
. From this old discussion I suspect that there is a bug in the key mapping for the Italian keyboard in a way similar to the bugs mentioned in the discussion for the French and German keyboard.