예제 #1
0
  public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(350);

    SwingUtilities.invokeAndWait(
        new Runnable() {

          public void run() {
            createAndShowGUI();
          }
        });

    robot.waitForIdle();

    SwingUtilities.invokeAndWait(
        new Runnable() {

          public void run() {
            spane.requestFocus();
            sbar.setValue(sbar.getMaximum());
          }
        });

    robot.waitForIdle();

    Point point = getClickPoint(0.5, 0.5);
    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);

    robot.waitForIdle();

    SwingUtilities.invokeAndWait(
        new Runnable() {

          public void run() {
            final int oldValue = sbar.getValue();
            sbar.addAdjustmentListener(
                new AdjustmentListener() {

                  public void adjustmentValueChanged(AdjustmentEvent e) {
                    if (e.getValue() >= oldValue) {
                      passed = false;
                    }
                    do_test = true;
                  }
                });
          }
        });

    robot.waitForIdle();

    point = getClickPoint(0.5, 0.2);
    robot.mouseMove(point.x, point.y);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.waitForIdle();

    if (!do_test || !passed) {
      throw new Exception("The scrollbar moved with incorrect direction");
    }
  }
예제 #2
0
  public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new NimbusLookAndFeel());

    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            createAndShowGUI();
          }
        });

    toolkit.realSync();

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            Component previewPanel =
                Util.findSubComponent(cc, "javax.swing.colorchooser.DefaultPreviewPanel");
            point = previewPanel.getLocationOnScreen();
          }
        });

    point.translate(5, 5);

    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
  }
  public static void main(String s[]) {

    // Getting save directory
    String saveDir;
    if (s.length > 0) {
      saveDir = s[0];
    } else {
      saveDir =
          JOptionPane.showInputDialog(
              null,
              "Please enter directory where "
                  + "the images is/will be saved\n\n"
                  + "Also possible to specifiy as argument 1 when "
                  + "running this program.",
              "l:\\webcamtest");
    }

    String layout = "";
    if (s.length > 1) {
      layout = s[1];
    }

    // Move mouse to the point 5000,5000 px (out of the screen)
    Robot rob;
    try {
      rob = new Robot();
      rob.setAutoDelay(500); // 0,5 s
      rob.mouseMove(5000, 5000);
    } catch (AWTException e) {
      e.printStackTrace();
    }

    // Make the main window
    JFrame frame = new JFrame();
    frame.setAlwaysOnTop(true);
    frame.setTitle(
        "Webcam capture and imagefading - "
            + "Vitenfabrikken Jærmuseet - "
            + "made by Hallvard Nygård - "
            + "Vitenfabrikken.no / Jaermuseet.no");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setUndecorated(true);

    WebcamCaptureAndFadePanel panel = new WebcamCaptureAndFadePanel(saveDir, layout);
    frame.getContentPane().add(panel);
    frame.addKeyListener(panel);
    frame.pack();

    frame.setVisible(true);
  }
  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!");
  }
 public void init() {
   try {
     robot = new Robot();
     robot.setAutoDelay(50);
   } catch (AWTException e) {
     throw new RuntimeException("Error: unable to create robot", e);
   }
   // Create instructions for the user here, as well as set up
   // the environment -- set the layout manager, add buttons,
   // etc.
   this.setLayout(new BorderLayout());
   Sysout.createDialogWithInstructions(
       new String[] {"Automatic test. Simply wait until it's done."});
 }
예제 #6
0
  public static void main(String[] args) throws Throwable {
    Robot robot = new Robot();
    robot.setAutoDelay(250);

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    SwingUtilities.invokeAndWait(
        new Runnable() {

          @Override
          public void run() {
            JFrame frame = new JFrame("Test");
            frame.setContentPane(createPanel(frame));
            frame.setJMenuBar(createMenuBar());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
          }
        });

    robot.waitForIdle();

    // Change the default button to
    // force a call to BasicRootPaneUI.updateDefaultButtonBindings()
    Util.hitKeys(robot, KeyEvent.VK_TAB);

    // If the bug exists, then as soon as the menu appears,
    // the VK_ENTER, VK_DOWN, VK_UP and VK_ESC will have no
    // effect.
    Util.hitMnemonics(robot, KeyEvent.VK_U);
    Util.hitKeys(robot, KeyEvent.VK_ENTER);
    robot.waitForIdle();

    checkAction();

    Util.hitMnemonics(robot, KeyEvent.VK_U);
    Util.hitKeys(robot, KeyEvent.VK_DOWN);
    Util.hitKeys(robot, KeyEvent.VK_ENTER);
    robot.waitForIdle();

    checkAction();
  }
예제 #7
0
  public static void main(String[] args) throws Exception {

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    Robot robot = new Robot();
    robot.setAutoDelay(20);
    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            // just to quickly grab a column model
            JTable table = new JTable(10, 5);
            header = new JTableHeader(table.getColumnModel());
            checkColumn(0, "A");
            JFrame frame = new JFrame("standalone header");
            frame.add(header);
            frame.pack();
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          }
        });
    robot.waitForIdle();
    Point point = header.getLocationOnScreen();
    robot.mouseMove(point.x + 3, point.y + 3);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    for (int i = 0; i < header.getWidth() - 3; i++) {
      robot.mouseMove(point.x + i, point.y + 3);
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            TableColumnModel model = header.getColumnModel();
            checkColumn(model.getColumnCount() - 1, "A");
          }
        });
  }
  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);
  }