public class BasicRobot_pressAndReleaseKeys_Test extends BasicRobot_TestCase {
@Test
public void should_press_and_release_given_keys() {
giveFocusToTextField();
final JTextField textField = window().textField();
final KeyRecorder recorder = KeyRecorder.attachTo(textField);
execute(new GuiTask() {
@Override
protected void executeInEDT() {
textField.setText("");
}
});
robot().waitForIdle();
robot().pressAndReleaseKeys(new int[] { VK_A, VK_B, VK_Z });
pause(new Condition("until keys VK_A, VK_B and VK_Z are pressed and released") {
@Override
public boolean test() {
Integer[] expectedKeys = array(VK_A, VK_B, VK_Z);
return recorder.keysWerePressed(expectedKeys) && recorder.keysWereReleased(expectedKeys);
}
}, timeout(500));
}