/** * Runs a sample test procedure * * @param robot the robot attached to the screen device */ public static void runTest(Robot robot) { // simulate a space bar press robot.keyPress(' '); robot.keyRelease(' '); // simulate a tab key followed by a space robot.delay(2000); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyPress(' '); robot.keyRelease(' '); // simulate a mouse click over the rightmost button robot.delay(2000); robot.mouseMove(200, 50); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); // capture the screen and show the resulting image robot.delay(2000); BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, 400, 300)); ImageFrame frame = new ImageFrame(image); frame.setVisible(true); }
public void start() { menu.setMnemonic('f'); submenu.setMnemonic('m'); menu.add(submenu); submenu.add(item); bar.add(menu); frame.setJMenuBar(bar); frame.pack(); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Sysout.println(e.toString()); synchronized (activated) { activated.set(true); activated.notifyAll(); } } }); frame.setVisible(true); Util.waitForIdle(robot); boolean isMacOSX = (OSInfo.getOSType() == OSInfo.OSType.MACOSX); if (isMacOSX) { robot.keyPress(KeyEvent.VK_CONTROL); robot.delay(20); } robot.keyPress(KeyEvent.VK_ALT); robot.delay(20); robot.keyPress(KeyEvent.VK_F); robot.delay(20); robot.keyRelease(KeyEvent.VK_F); robot.delay(20); robot.keyRelease(KeyEvent.VK_ALT); if (isMacOSX) { robot.keyRelease(KeyEvent.VK_CONTROL); robot.delay(20); } Util.waitForIdle(robot); robot.keyPress(KeyEvent.VK_M); robot.delay(20); robot.keyRelease(KeyEvent.VK_M); Util.waitForIdle(robot); robot.keyPress(KeyEvent.VK_SPACE); robot.delay(20); robot.keyRelease(KeyEvent.VK_SPACE); Util.waitForIdle(robot); if (!Util.waitForCondition(activated, 2000)) { throw new TestFailedException("a submenu wasn't activated by mnemonic key press"); } Sysout.println("Test passed."); }
public static void main(String[] args) throws Exception { robot = new Robot(); robot.setAutoDelay(50); try { SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { createAndShowGUI(); } }); robot.waitForIdle(); checkFocusOwner(textField); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.waitForIdle(); checkFocusOwner(button); robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_SHIFT); robot.waitForIdle(); checkFocusOwner(textField); robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_SHIFT); robot.waitForIdle(); checkFocusOwner(button); } finally { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (frame != null) { frame.dispose(); } } }); } System.out.println("Test Passed!"); }
// Set if the application is in editing mode based on the state of the shift key public void setEditingMode() { try { Robot robot = new Robot(); robot.keyRelease(KeyEvent.VK_SHIFT); } catch (AWTException e) { e.printStackTrace(); } }
void test() { robot.waitForIdle(); if (!text.isFocusOwner()) { robot.mouseMove(text.getLocationOnScreen().x + 5, text.getLocationOnScreen().y + 5); robot.delay(100); robot.mousePress(MouseEvent.BUTTON1_MASK); robot.delay(100); robot.mouseRelease(MouseEvent.BUTTON1_MASK); int iter = 10; while (!text.isFocusOwner() && iter-- > 0) { robot.delay(200); } if (iter <= 0) { Sysout.println("Test: text field couldn't be focused!"); return; } } robot.keyPress(KeyEvent.VK_A); robot.delay(100); robot.keyRelease(KeyEvent.VK_A); robot.waitForIdle(); String charA = text.getText(); System.err.println("Test: character typed with VK_A: " + charA); robot.keyPress(KeyEvent.VK_BACK_SPACE); robot.delay(100); robot.keyRelease(KeyEvent.VK_BACK_SPACE); robot.waitForIdle(); if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) { robot.keyPress(KeyEvent.VK_CONTROL); } robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_F); robot.delay(100); robot.keyRelease(KeyEvent.VK_F); robot.keyRelease(KeyEvent.VK_ALT); if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) { robot.keyRelease(KeyEvent.VK_CONTROL); } robot.waitForIdle(); String string = text.getText(); robot.keyPress(KeyEvent.VK_I); robot.delay(100); robot.keyRelease(KeyEvent.VK_I); robot.waitForIdle(); Sysout.println("Test: character typed after mnemonic key press: " + text.getText()); if (!text.getText().equals(string)) { throw new RuntimeException("Test failed!"); } robot.keyPress(KeyEvent.VK_A); robot.delay(100); robot.keyRelease(KeyEvent.VK_A); robot.waitForIdle(); System.err.println("Test: chracter typed with VK_A: " + text.getText()); if (!charA.equals(text.getText())) { throw new RuntimeException("Test failed!"); } Sysout.println("Test passed."); }
public static void main(String[] args) throws Throwable { sun.awt.SunToolkit toolkit = (sun.awt.SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { test = new TaskbarPositionTest(); } }); // Use Robot to automate the test Robot robot; robot = new Robot(); robot.setAutoDelay(125); // 1 - menu Util.hitMnemonics(robot, KeyEvent.VK_1); toolkit.realSync(); isPopupOnScreen(menu1.getPopupMenu(), screenBounds); // 2 menu with sub menu robot.keyPress(KeyEvent.VK_RIGHT); robot.keyRelease(KeyEvent.VK_RIGHT); Util.hitMnemonics(robot, KeyEvent.VK_S); toolkit.realSync(); isPopupOnScreen(menu2.getPopupMenu(), screenBounds); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); // Focus should go to non editable combo box toolkit.realSync(); Thread.sleep(500); robot.keyPress(KeyEvent.VK_DOWN); // How do we check combo boxes? // Editable combo box robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); // combo1.getUI(); // Popup from Text field robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_CONTROL); // Popup from a mouse click. Point pt = new Point(2, 2); SwingUtilities.convertPointToScreen(pt, panel); robot.mouseMove((int) pt.getX(), (int) pt.getY()); robot.mousePress(InputEvent.BUTTON3_MASK); robot.mouseRelease(InputEvent.BUTTON3_MASK); toolkit.realSync(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { test.setLocation(-30, 100); combo1.addPopupMenuListener(new ComboPopupCheckListener()); combo1.requestFocus(); } }); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); robot.keyPress(KeyEvent.VK_ESCAPE); robot.keyRelease(KeyEvent.VK_ESCAPE); toolkit.realSync(); Thread.sleep(500); }