Exemplo n.º 1
0
  /**
   * 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);
  }
Exemplo n.º 2
0
 public void drawTo(Point start, Point end) {
   robot.mouseMove((int) start.getX(), (int) start.getY());
   robot.mousePress(InputEvent.BUTTON1_MASK);
   robot.delay(100);
   robot.mouseMove((int) end.getX(), (int) end.getY());
   robot.delay(100);
   robot.mouseRelease(InputEvent.BUTTON1_MASK);
   robot.delay(100);
 }
  public static void main(String s[]) {
    initParams(s);
    initAdapters();
    f = new Frame();
    final int[] modifiers = {InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK};
    final String[] modifierNames = {"InputEvent.SHIFT_MASK", "InputEvent.CTRL_MASK"};
    f.setLayout(new FlowLayout());
    f.addMouseWheelListener(
        new MouseWheelListener() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            System.out.println("WHEEL " + e);
          }
        });
    f.setSize(300, 300);
    f.setVisible(true);

    try {
      robot = new Robot();
      robot.delay(500);
      robot.mouseMove(
          f.getLocationOnScreen().x + f.getWidth() / 2,
          f.getLocationOnScreen().y + f.getHeight() / 2);
      if (autorun) {
        // testing buttons 1, 2, 3 only
        testPlainButtons();
        robot.delay(500);

        // testing buttons 1, 2, 3 with SHIFT, CTRL, ALT keyboard modifiers
        testButtonsWithShift();
        robot.delay(500);

        testButtonsWithControl();
        robot.delay(500);

        testButtonsWithAlt();
        robot.delay(500);
      } else {
        switch (testModifier) {
          case SHIFT:
            f.addMouseListener(adapterTest2);
            break;
          case CTRL:
            f.addMouseListener(adapterTest3);
            break;
          case ALT:
            f.addMouseListener(adapterTest4);
            break;
          default: // NONE inclusive
            f.addMouseListener(adapterTest1);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException("Test failed.");
    }
  }
 // test BUTTON1, 2 and 3 without any modifiers keys
 public static void testPlainButtons() {
   System.out.println("Testing buttons without modifiers.");
   f.addMouseListener(adapterTest1);
   for (int button : mouseButtons) {
     robot.mousePress(button);
     robot.delay(100);
     robot.mouseRelease(button);
   }
   robot.delay(1000);
   f.removeMouseListener(adapterTest1);
 }
 // test BUTTON1, 2 and 3 with ALT key
 public static void testButtonsWithAlt() {
   System.out.println("Testing buttons with ALT modifier.");
   f.addMouseListener(adapterTest4);
   for (int button : mouseButtons) {
     robot.keyPress(KeyEvent.VK_ALT);
     robot.mousePress(button);
     robot.delay(100);
     robot.mouseRelease(button);
     robot.keyRelease(KeyEvent.VK_ALT);
   }
   robot.delay(1000);
   f.removeMouseListener(adapterTest4);
 }
Exemplo n.º 6
0
  public static void main(String[] s) {
    JFrame frame = new JFrame("A test frame");
    JPanel outputBox = new JPanel();
    JButton jButton = new JButton();

    frame.setSize(200, 200);
    frame.addMouseWheelListener(
        new MouseWheelListener() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            System.out.println("Wheel moved on FRAME : " + e);
            actualEvents++;
          }
        });

    outputBox.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            System.out.println("MousePressed on OUTBOX : " + e);
          }
        });
    frame.add(outputBox);
    outputBox.add(jButton);

    frame.setVisible(true);

    Util.waitForIdle(robot);

    Util.pointOnComp(jButton, robot);
    Util.waitForIdle(robot);

    for (int i = 0; i < MOVE_COUNT; i++) {
      robot.mouseWheel(1);
      robot.delay(10);
    }

    for (int i = 0; i < MOVE_COUNT; i++) {
      robot.mouseWheel(-1);
      robot.delay(10);
    }

    Util.waitForIdle(robot);
    // Not fair to check for multiplier 4 as it's not specified actual number of WheelEvents
    // result in a single wheel rotation.
    if (actualEvents != EXPECTED_COUNT) {
      AbstractTest.fail(
          "Expected events count: " + EXPECTED_COUNT + " Actual events count: " + actualEvents);
    }
  }
Exemplo n.º 7
0
 public MouseController() throws AWTException {
   // auto delay after each events
   robot.setAutoDelay(40);
   robot.setAutoWaitForIdle(true);
   robot.delay(5000);
   this.drawSomething();
   this.drawCercle(new Point(846, 467), new Point(992, 603));
   this.drawCercle(new Point(100, 100), new Point(300, 300));
   this.drawCercle(new Point(500, 500), new Point(900, 200));
 }
Exemplo n.º 8
0
  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 void ClickingLogic(int Ammount, int delay) {
    robot.mouseMove(var_coordX, var_coordY);
    robot.setAutoDelay(40);
    robot.setAutoWaitForIdle(true);

    for (int i = 0; i < Ammount; i++) {
      // robot.mouseMove(var_coordX,var_coordY); to include or not to include
      robot.delay(delay);
      robot.mousePress(InputEvent.BUTTON1_MASK);
      robot.mouseRelease(InputEvent.BUTTON1_MASK);
      var_ammount++;
      scene_ClickCount.setText(String.valueOf(var_ammount));
    }
  }
Exemplo n.º 10
0
  /** Do screen capture and save it as image */
  private static void captureScreenAndSave() {

    try {
      Robot robot = new Robot();
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
      System.out.println("About to screen capture - " + rectangle);
      java.awt.image.BufferedImage image = robot.createScreenCapture(rectangle);
      javax.imageio.ImageIO.write(image, "jpg", new java.io.File("ScreenImage.jpg"));
      robot.delay(3000);
    } catch (Throwable t) {
      System.out.println("WARNING: Exception thrown while screen capture!");
      t.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.");
  }
Exemplo n.º 12
0
 public void selectTool(Point2D tool) {
   robot.mouseMove((int) tool.getX(), (int) tool.getY());
   robot.mousePress(InputEvent.BUTTON1_MASK);
   robot.delay(100);
   robot.mouseRelease(InputEvent.BUTTON1_MASK);
 }
Exemplo n.º 13
0
  private void test(TestState currentState) throws InterruptedException, InvocationTargetException {

    synchronized (LOCK) {
      this.currentState = currentState;
      System.out.println(this.currentState);

      List list;
      if (currentState.getMultiple()) {
        list = multiple;
      } else {
        list = single;
      }

      Robot r;
      try {
        r = new Robot();
      } catch (AWTException e) {
        throw new RuntimeException(e.getMessage());
      }

      r.delay(10);
      Point loc = this.getLocationOnScreen();

      r.mouseMove(loc.x + 10, loc.y + 10);
      r.mousePress(InputEvent.BUTTON1_MASK);
      r.delay(10);
      r.mouseRelease(InputEvent.BUTTON1_MASK);
      r.delay(10);

      list.requestFocusInWindow();
      LOCK.wait(ACTION_TIMEOUT);
      if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list) {
        throw new RuntimeException("Test failed - list isn't focus owner.");
      }

      list.deselect(0);
      list.deselect(1);
      list.deselect(2);
      list.deselect(3);
      list.deselect(4);
      list.deselect(5);
      list.deselect(6);
      list.deselect(7);
      list.deselect(8);

      int selectIndex = 0;
      int visibleIndex = 0;

      if (currentState.getScrollMoved()) {

        if (currentState.getKeyID() == KeyEvent.VK_PAGE_UP
            || currentState.getKeyID() == KeyEvent.VK_HOME) {
          selectIndex = 8;
          visibleIndex = 8;
        } else if (currentState.getKeyID() == KeyEvent.VK_PAGE_DOWN
            || currentState.getKeyID() == KeyEvent.VK_END) {
          selectIndex = 0;
          visibleIndex = 0;
        }

      } else {

        if (currentState.getKeyID() == KeyEvent.VK_PAGE_UP
            || currentState.getKeyID() == KeyEvent.VK_HOME) {

          if (currentState.getSelectedMoved()) {
            selectIndex = 1;
            visibleIndex = 0;
          } else {
            selectIndex = 0;
            visibleIndex = 0;
          }

        } else if (currentState.getKeyID() == KeyEvent.VK_PAGE_DOWN
            || currentState.getKeyID() == KeyEvent.VK_END) {

          if (currentState.getSelectedMoved()) {
            selectIndex = 7;
            visibleIndex = 8;
          } else {
            selectIndex = 8;
            visibleIndex = 8;
          }
        }
      }

      list.select(selectIndex);
      list.makeVisible(visibleIndex);

      r.delay(10);

      if (currentState.getKeyID() == KeyEvent.VK_HOME
          || currentState.getKeyID() == KeyEvent.VK_END) {
        r.keyPress(KeyEvent.VK_CONTROL);
      }

      r.delay(10);
      r.keyPress(currentState.getKeyID());
      r.delay(10);
      r.keyRelease(currentState.getKeyID());
      r.delay(10);

      if (currentState.getKeyID() == KeyEvent.VK_HOME
          || currentState.getKeyID() == KeyEvent.VK_END) {
        r.keyRelease(KeyEvent.VK_CONTROL);
      }

      r.waitForIdle();
      r.delay(200);

      if (currentState.getTemplate() != currentState.getAction())
        throw new RuntimeException("Test failed.");
    }
  }