I'm writing some integration tests using a robot. I have the robot opening a menu and it should be selecting one of the options form the menu; except the enter key seems to be ignored. The menu will open and the correct menu item is selected, but no action has been taken as it should if I hit enter. If I manually press the appropriate keys it does what is expected. If I run the robot on a non-java application the other application will respond to the enter event correctly. So I've verified that I'm sending an enter event correctly and that java menu should respond to it; but something isn't working.
I've also tried replacing the enter event with a space event (with the menu should also respond to) and got no response either.
I'm running on redhat linux with the latest sun JDK. I'm pretty sure it's not an obvious problem with my code since I've found this post describing someone who ran into the exact same problem, but it has no solution: http://www.velocityreviews.com/forums/t666100-robot-and-awt-on-linux.html
private void requestTest(String testName){
if(testName==currentTest)
return;
//overwrite config file with new data
currentTest=testName;
overwriteFile(configFile, getCurrentConfigFile());
//close current graph
pressKeyCombo(KeyEvent.VK_CONTROL, KeyEvent.VK_F4);
//open File menu
pressKeyCombo(KeyEvent.VK_ALT, KeyEvent.VK_F);
//select the 'load defaults' option
pressKey(KeyEvent.VK_DOWN);
pressKey(KeyEvent.VK_DOWN);
pressKey(KeyEvent.VK_DOWN);
pressKey(KeyEvent.VK_SPACE);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…