Ejemplo n.º 1
0
  // The difference between X-system and Win32: on Win32 Dragged event start to be generated after
  // any mouse drag.
  // On X-systems Dragged event first fired when mouse has left the SMUDGE area
  public void smallWin32Drag(int pixelsX, int pixelsY) {
    // by the X-axis
    robot.mouseMove(fp.x + frame.getWidth() / 2, fp.y + frame.getHeight() / 2);
    // drag for a short distance
    robot.mousePress(InputEvent.BUTTON1_MASK);
    System.out.println(" pixelsX = " + pixelsX + " pixelsY = " + pixelsY);
    for (int i = 1; i <= pixelsX; i++) {
      System.out.println("Moving a mouse by X");
      robot.mouseMove(fp.x + frame.getWidth() / 2 + i, fp.y + frame.getHeight() / 2);
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (!dragged) {
      throw new RuntimeException(
          "Test failed. Dragged event (by the X-axis) didn't occur in the SMUDGE area. Dragged = "
              + dragged);
    }

    // the same with Y-axis
    robot.mouseMove(fp.x + frame.getWidth() / 2, fp.y + frame.getHeight() / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    for (int i = 1; i <= pixelsY; i++) {
      System.out.println("Moving a mouse by Y");
      robot.mouseMove(fp.x + frame.getWidth() / 2, fp.y + frame.getHeight() / 2 + i);
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (!dragged) {
      throw new RuntimeException(
          "Test failed. Dragged event (by the Y-axis) didn't occur in the SMUDGE area. Dragged = "
              + dragged);
    }
  }
Ejemplo n.º 2
0
  public void smallDrag(int pixelsX, int pixelsY) {
    // by the X-axis
    robot.mouseMove(fp.x + frame.getWidth() / 2, fp.y + frame.getHeight() / 2);
    // drag for a short distance
    robot.mousePress(InputEvent.BUTTON1_MASK);
    for (int i = 1; i < pixelsX; i++) {
      robot.mouseMove(fp.x + frame.getWidth() / 2 + i, fp.y + frame.getHeight() / 2);
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (dragged) {
      throw new RuntimeException(
          "Test failed. Dragged event (by the X-axis) occured in SMUDGE area. Dragged = "
              + dragged
              + ". Clicked = "
              + clicked);
    }

    // the same with Y-axis
    robot.mouseMove(fp.x + frame.getWidth() / 2, fp.y + frame.getHeight() / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    for (int i = 1; i < pixelsY; i++) {
      robot.mouseMove(fp.x + frame.getWidth() / 2, fp.y + frame.getHeight() / 2 + i);
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (dragged) {
      throw new RuntimeException(
          "Test failed. Dragged event (by the Y-axis) occured in SMUDGE area. Dragged = "
              + dragged
              + ". Clicked = "
              + clicked);
    }
  }
Ejemplo n.º 3
0
  public static void main(String[] argv) throws AWTException {
    final JFrame f = new JFrame("Robot Test");
    final JButton b = new JButton("Click me");
    final JTextField tf = new JTextField();
    final RobotTest t = new RobotTest();
    f.add(tf, BorderLayout.NORTH);
    f.add(t, BorderLayout.CENTER);
    f.add(b, BorderLayout.SOUTH);
    f.pack();
    f.setLocation(0, 0);
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            f.dispose();
          }
        });
    f.setVisible(true);

    final Robot r = new Robot();
    r.setAutoDelay(50);
    r.delay(1000);
    image = r.createScreenCapture(new Rectangle(0, 0, 200, 200));
    t.repaint();
    //        for(int i = 0; i < 400; i++){
    //            r.mouseMove(i, i);
    //        }

    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            tf.setText("Clicked !");
          }
        });

    moveToCenterOfComponent(r, b);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    Point p = f.getLocationOnScreen();
    p.translate(f.getWidth() / 2, 5);
    r.mouseMove((int) p.getX(), (int) p.getY());
    r.mousePress(InputEvent.BUTTON1_MASK);
    for (int i = 0; i < 100; i++) {
      r.mouseMove((int) p.getX() + i, (int) p.getY() + i);
    }
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    t.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseMoved(MouseEvent event) {
            Point p = event.getPoint();
            SwingUtilities.convertPointToScreen(p, t);
            crtColor = r.getPixelColor(p.x, p.y);
            // Graphics g = t.getGraphics();
            // g.setColor(crtColor);
            // g.fillRect(25,225, 50,50);
            t.repaint();
          }
        });
  }
Ejemplo n.º 4
0
  private void _doHoldOneButtonAndPressAnother(final int keyCode, final int keyModifierMask)
      throws Exception {

    if (_debug) {
      _debugPrintStream.println("\n>>>> _doHoldOneButtonAndPressAnother");
    }

    _doKeyPress(keyCode);

    for (int n = 0; n < _numButtonsToTest; ++n) {

      int awtButtonMask = _awtButtonMasks[n];

      if (_debug) {
        _debugPrintStream.println("*** pressing button " + (n + 1));
      }
      _testMouseListener.setExpectedModifiers(
          _getNewtModifiersForAwtExtendedModifiers(keyModifierMask | awtButtonMask));
      _robot.mousePress(awtButtonMask);
      _checkFailures("mouse-press(" + (n + 1) + ")", 1);

      for (int m = 0; m < _numButtonsToTest; ++m) {

        if (n != m) {

          if (_debug) {
            _debugPrintStream.println("*** pressing additional button " + (m + 1));
          }
          _testMouseListener.setExpectedModifiers(
              _getNewtModifiersForAwtExtendedModifiers(
                  keyModifierMask | awtButtonMask | _awtButtonMasks[m]));
          _robot.mousePress(_awtButtonMasks[m]);
          _checkFailures("mouse-press(" + (n + 1) + ", " + (m + 1) + ")", 1);

          if (_debug) {
            _debugPrintStream.println("*** releasing additional button " + (m + 1));
          }
          _testMouseListener.setExpectedModifiers(
              _getNewtModifiersForAwtExtendedModifiers(
                  keyModifierMask | awtButtonMask | _awtButtonMasks[m]));
          _robot.mouseRelease(_awtButtonMasks[m]);
          _checkFailures("mouse-release(" + (n + 1) + ", " + (m + 1) + ")", 1);
        }
      }

      if (_debug) {
        _debugPrintStream.println("*** releasing button " + (n + 1));
      }
      _testMouseListener.setExpectedModifiers(
          _getNewtModifiersForAwtExtendedModifiers(keyModifierMask | awtButtonMask));
      _robot.mouseRelease(awtButtonMask);
      _checkFailures("mouse-release(" + (n + 1) + ")", 1);
    }

    _doKeyRelease(keyCode);
  }
Ejemplo n.º 5
0
  public static void clickVWall(BoardGui frame, Robot bot, Board board, int sectNum) {
    int xInstersectOffset = 7;
    int yInstersectOffset = 51;
    // Rest for a little while
    try {
      Thread.sleep(900, 000);
    } catch (InterruptedException e) {
    }

    // Intersects
    bot.mouseMove(
        frame.sect.get(sectNum).getX() + xInstersectOffset,
        frame.sect.get(sectNum).getY() + yInstersectOffset);

    bot.mousePress(InputEvent.BUTTON1_MASK);
    // add time between press and release or the input event system may
    // not think it is a click
    try {
      Thread.sleep(250);
    } catch (InterruptedException e) {
    }
    bot.mouseRelease(InputEvent.BUTTON1_MASK);

    // Rest for a little while
    try {
      Thread.sleep(300, 000);
    } catch (InterruptedException e) {
    }

    // Intersects
    bot.mouseMove(
        frame.sect.get(sectNum).getX() + xInstersectOffset,
        frame.sect.get(sectNum).getY() + yInstersectOffset);

    bot.mousePress(InputEvent.BUTTON1_MASK);
    // add time between press and release or the input event system may
    // not think it is a click
    try {
      Thread.sleep(250);
    } catch (InterruptedException e) {
    }
    bot.mouseRelease(InputEvent.BUTTON1_MASK);

    try {
      Thread.sleep(250);
    } catch (InterruptedException e) {
    }
    frame.submitVWall();

    frame.labels[board.getCurrPlayer()].setText(
        "\t\t\t " + board.getWallCount(board.getCurrPlayer()) + " walls remain");
    frame.labels[board.getCurrPlayer()].repaint();

    frame.control.iteratePlayers(board, board.getPlayerCount());
  }
Ejemplo n.º 6
0
  @Override
  protected boolean performTest() {
    try {
      SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              // prepare test data
              frameClicked = 0;

              b.requestFocus();

              scrollPane.getHorizontalScrollBar().setUnitIncrement(40);
              scrollPane.getVerticalScrollBar().setUnitIncrement(40);

              hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();
              hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3);
              vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();
              vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3);

              testLoc = p.getLocationOnScreen();
              testLoc.translate(-3, -3);

              resizeLoc = f.getLocationOnScreen();
              resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1);
            }
          });
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException("Problem preparing test GUI.");
    }
    // run robot
    Robot robot = Util.createRobot();
    robot.setAutoDelay(ROBOT_DELAY);

    robot.mouseMove(hLoc.x, hLoc.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    Util.waitForIdle(robot);

    robot.mouseMove(vLoc.x, vLoc.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    Util.waitForIdle(robot);

    clickAndBlink(robot, testLoc, false);
    robot.mouseMove(resizeLoc.x, resizeLoc.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseMove(resizeLoc.x + 5, resizeLoc.y + 5);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    Util.waitForIdle(robot);

    clickAndBlink(robot, testLoc, false);
    return frameClicked == 2;
  }
Ejemplo n.º 7
0
    /**
     * This method clicks into the middle of a document. It uses Accessibility to get the document
     * and query for its position and its range to calculate the middle. This values was used for
     * <CODE>Robot</CODE> Class. This Robot class is able to move the mouse and to click a mouse
     * button
     *
     * @see java.awt.Robot
     */
    private void clickIntoDoc() {
      try {
        // get the position and the range of a scroll bar

        XWindow xWindow = AccessibilityTools.getCurrentWindow(xModel);

        XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

        XAccessibleContext xPanel =
            AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
        XAccessibleComponent xPanelCont =
            UnoRuntime.queryInterface(XAccessibleComponent.class, xPanel);

        // the position of the panel
        Point point = xPanelCont.getLocationOnScreen();

        // the range of the panel
        Rectangle rect = xPanelCont.getBounds();

        try {
          Robot rob = new Robot();
          int x = point.X + (rect.Width / 2);
          int y = point.Y + (rect.Height / 2);
          System.out.println("try to click into the middle of the document");
          rob.mouseMove(x, y);
          rob.mousePress(InputEvent.BUTTON1_MASK);
          rob.mouseRelease(InputEvent.BUTTON1_MASK);
        } catch (java.awt.AWTException e) {
          System.out.println("couldn't press mouse button");
        }
      } catch (java.lang.Exception e) {
        System.out.println("could not click into the scroll bar: " + e.toString());
      }
    }
Ejemplo n.º 8
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);
  }
Ejemplo n.º 9
0
  public static void main(final String[] args) throws AWTException {
    final boolean dump = Boolean.parseBoolean(args[0]);
    final Window w =
        new Frame() {
          @Override
          public void list(final PrintStream out, final int indent) {
            super.list(out, indent);
            dumped = true;
          }
        };
    w.setSize(200, 200);
    w.setLocationRelativeTo(null);
    w.setVisible(true);

    final Robot robot = new Robot();
    robot.setAutoDelay(50);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(w.getX() + w.getWidth() / 2, w.getY() + w.getHeight() / 2);
    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    w.dispose();
    if (dumped != dump) {
      throw new RuntimeException("Exp:" + dump + ", actual:" + dumped);
    }
  }
Ejemplo n.º 10
0
  public static void requestFocus(Project project, final boolean useRobot) {
    JFrame frame = WindowManager.getInstance().getFrame(project);

    // the only reliable way I found to bring it to the top
    boolean aot = frame.isAlwaysOnTop();
    frame.setAlwaysOnTop(true);
    frame.setAlwaysOnTop(aot);

    int frameState = frame.getExtendedState();
    if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) {
      // restore the frame if it is minimized
      frame.setExtendedState(frameState ^ Frame.ICONIFIED);
    }
    frame.toFront();
    frame.requestFocus();
    if (useRobot && runningOnWindows7()) {
      try {
        // remember the last location of mouse
        final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

        // simulate a mouse click on title bar of window
        Robot robot = new Robot();
        robot.mouseMove(frame.getX(), frame.getY());
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

        // move mouse to old location
        robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
      } catch (Exception ex) {
        // just ignore exception, or you can handle it as you want
      } finally {
        frame.setAlwaysOnTop(false);
      }
    }
  }
Ejemplo n.º 11
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);
  }
 protected void handleButtonClickDown(
     boolean buttonDownInCurrentEvent, boolean buttonDownInPastEvents, int buttonKeyToActivate) {
   if (buttonDownInCurrentEvent) {
     if (buttonDownInPastEvents) {
       // Can resent special events back to the eventheap
       System.out.println("Drag");
     } else {
       // Set the states to create semi modal
       switch (buttonKeyToActivate) {
         case InputEvent.BUTTON1_MASK:
           {
             leftIsDown = true;
             break;
           }
         case InputEvent.BUTTON2_MASK:
           {
             middleIsDown = true;
             break;
           }
         case InputEvent.BUTTON3_MASK:
           {
             rightIsDown = true;
             break;
           }
       }
       robot.mousePress(buttonKeyToActivate);
     }
   }
 }
Ejemplo n.º 13
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");
    }
  }
 public void clickComponement(final Component comp, int delay) {
   pointOnComp(comp, robot);
   robot.delay(delay);
   robot.mousePress(InputEvent.BUTTON1_MASK);
   robot.delay(delay);
   robot.mouseRelease(InputEvent.BUTTON1_MASK);
 }
Ejemplo n.º 15
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);
 }
Ejemplo n.º 16
0
 public void execute() {
   Robot robot = getRobot();
   robot.mouseMove(xAxis, yAxis);
   robot.delay(200);
   robot.mousePress(InputEvent.BUTTON1_MASK);
   robot.delay(200);
   robot.mouseRelease(InputEvent.BUTTON1_MASK);
   robot.delay(200);
 }
 // 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);
 }
Ejemplo n.º 18
0
 public void run() {
   try {
     robot = new Robot();
     while (true) {
       Thread.sleep(time);
       robot.mousePress(InputEvent.BUTTON1_MASK);
       robot.mouseRelease(InputEvent.BUTTON1_MASK);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 19
0
 /**
  * Scrolls to a component then left clicks on it.
  *
  * @param o component to be clicked
  */
 protected void scrollToAndClickComponent(SGuiObject o) {
   scrollToComponent(o);
   Rectangle compRect = getComponentBounds(o);
   try {
     robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY());
     robot.mousePress(KeyEvent.BUTTON1_MASK);
     robot.mouseRelease(KeyEvent.BUTTON1_MASK);
     testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
   } catch (NullPointerException npe) {
     Log.debug("IGNORING Selenium NPE for scrollToAndClick '" + o.getWindowId() + "':", npe);
     testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
   }
 }
 // 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);
 }
Ejemplo n.º 21
0
  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));
    }
  }
Ejemplo n.º 22
0
  private void _doSingleButtonClickAndDrag(final int keyCode, final int keyModifierMask)
      throws Exception {

    if (_debug) {
      _debugPrintStream.println("\n>>>> _doSingleButtonClickAndDrag");
    }

    _doKeyPress(keyCode);

    _testMouseListener.setModifierCheckEnabled(true);

    for (int n = 0; n < _numButtonsToTest; ++n) {

      int awtButtonMask = _awtButtonMasks[n];

      if (_debug) {
        _debugPrintStream.println("*** pressing button " + (n + 1));
      }
      _testMouseListener.setExpectedModifiers(
          _getNewtModifiersForAwtExtendedModifiers(keyModifierMask | awtButtonMask));
      _robot.mousePress(awtButtonMask);
      _checkFailures("mouse-press(" + (n + 1) + ")", 1);

      // To get a drag we only need to move one pixel.
      if (_debug) {
        _debugPrintStream.println("*** moving mouse");
      }
      final int newX = INITIAL_MOUSE_X + 8, newY = INITIAL_MOUSE_Y + 8;
      _robot.mouseMove(newX, newY);
      _robot.delay(MS_ROBOT_MOUSE_MOVE_DELAY);
      _checkFailures("mouse-move(" + newX + ", " + newY + ")", 1);

      if (_debug) {
        _debugPrintStream.println("*** releasing button " + (n + 1));
      }
      _testMouseListener.setExpectedModifiers(
          _getNewtModifiersForAwtExtendedModifiers(keyModifierMask | awtButtonMask));
      _robot.mouseRelease(awtButtonMask);
      _checkFailures("mouse-release(" + (n + 1) + ")", 1);

      _testMouseListener.setModifierCheckEnabled(false);
      _robot.mouseMove(INITIAL_MOUSE_X, INITIAL_MOUSE_Y);
      _robot.delay(MS_ROBOT_MOUSE_MOVE_DELAY);
      _testMouseListener.setModifierCheckEnabled(true);
    }

    _doKeyRelease(keyCode);
  }
Ejemplo n.º 23
0
  protected boolean clickOnSheet(Point point) {
    log.println("Clicking in the center of the AccessibleSpreadsheet");

    try {
      Robot rob = new Robot();
      rob.mouseMove(point.X, point.Y);
      rob.mousePress(InputEvent.BUTTON1_MASK);
      util.utils.shortWait(1000);
      rob.mouseRelease(InputEvent.BUTTON1_MASK);
      util.utils.shortWait(1000);
    } catch (java.awt.AWTException e) {
      log.println("couldn't press mouse button");
    }

    return true;
  }
  @Test
  public void test() throws AWTException, InvocationTargetException, InterruptedException {
    Main window = new Main();
    waitForSwing();

    JComboBox<String> combo = window.getCombo();
    Dimension comboSizes = combo.getSize();
    Rectangle comboBounds = combo.getBounds();

    Point windowLocation = window.getLocation();
    Point comboLocation = combo.getLocation();

    Rectangle realBounds =
        new Rectangle(
            (int) comboBounds.getX(),
            (int) comboBounds.getY(),
            (int) comboSizes.getWidth(),
            (int) comboSizes.getHeight());

    assertEquals(realBounds, comboBounds);

    int posX = (int) (windowLocation.getX() + comboLocation.getX() + realBounds.getWidth()) - 1;
    int posY = (int) (windowLocation.getY() + comboLocation.getY() + realBounds.getHeight()) - 1;

    System.out.println("Window location: " + windowLocation);
    System.out.println("Combo location: " + comboLocation);
    System.out.println("Real Bounds: " + realBounds);
    System.out.println("Clicking at position: " + posX + " " + posY);

    // Click into the corner...
    Robot bot = new Robot();
    bot.mouseMove(posX, posY);
    bot.mousePress(InputEvent.BUTTON1_MASK);
    System.err.println("Mouse pressed.");
    waitForSwing();

    // While we hold down the mouse, the popup should be open
    assertTrue(combo.isPopupVisible());

    // If we release the mouse, it should still open...
    bot.mouseMove(posX, posY); // maybe the mouse got moved while the test was running
    bot.mouseRelease(InputEvent.BUTTON1_MASK);
    System.err.println("Mouse released.");
    waitForSwing();
    assertTrue(combo.isPopupVisible());
  }
Ejemplo n.º 25
0
 public void checkClicked() {
   robot.mouseMove(fp.x + frame.getWidth() / 2, fp.y + frame.getHeight() / 2);
   robot.mousePress(InputEvent.BUTTON1_MASK);
   robot.delay(10);
   robot.mouseRelease(InputEvent.BUTTON1_MASK);
   robot.delay(1000);
   if (!clicked || !pressed || !released || dragged) {
     throw new RuntimeException(
         "Test failed. Some of Pressed/Released/Clicked events are missed or dragged occured. Pressed/Released/Clicked/Dragged = "
             + pressed
             + ":"
             + released
             + ":"
             + clicked
             + ":"
             + dragged);
   }
 }
Ejemplo n.º 26
0
  // We need in this constructor to pass frame position between JVMs
  public FileListBetweenJVMsTest(
      Point targetFrameLocation, Point dragSourcePoint, int transferredFilesNumber)
      throws InterruptedException {
    TargetFileListFrame targetFrame =
        new TargetFileListFrame(targetFrameLocation, transferredFilesNumber);

    Util.waitForIdle(null);

    final Robot robot = Util.createRobot();

    robot.mouseMove((int) dragSourcePoint.getX(), (int) dragSourcePoint.getY());
    sleep(100);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    sleep(100);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    sleep(100);

    Util.drag(robot, dragSourcePoint, targetFrame.getDropTargetPoint(), InputEvent.BUTTON1_MASK);
  }
Ejemplo n.º 27
0
  private void _doPressAllButtonsInSequence(final int keyCode, final int keyModifierMask)
      throws Exception {

    if (_debug) {
      _debugPrintStream.println("\n>>>> _doPressAllButtonsInSequence");
    }

    _doKeyPress(keyCode);

    {
      int cumulativeAwtModifiers = 0;

      for (int n = 0; n < _numButtonsToTest; ++n) {

        cumulativeAwtModifiers |= _awtButtonMasks[n];

        if (_debug) {
          _debugPrintStream.println("*** pressing button " + (n + 1));
        }
        _testMouseListener.setExpectedModifiers(
            _getNewtModifiersForAwtExtendedModifiers(keyModifierMask | cumulativeAwtModifiers));
        _robot.mousePress(_awtButtonMasks[n]);
        _checkFailures("mouse-press(" + (n + 1) + ")", 1);
      }

      for (int n = _numButtonsToTest - 1; n >= 0; --n) {

        if (_debug) {
          _debugPrintStream.println("*** releasing button " + (n + 1));
        }
        _testMouseListener.setExpectedModifiers(
            _getNewtModifiersForAwtExtendedModifiers(keyModifierMask | cumulativeAwtModifiers));
        _robot.mouseRelease(_awtButtonMasks[n]);
        _checkFailures("mouse-release(" + (n + 1) + ")", 1);

        cumulativeAwtModifiers &= ~_awtButtonMasks[n];
      }
    }

    _doKeyRelease(keyCode);
  }
Ejemplo n.º 28
0
  public void oneDrag(int pixels) {
    robot.mouseMove(fp.x + frame.getWidth() / 2, fp.y + frame.getHeight() / 2);
    // drag for a short distance
    robot.mousePress(InputEvent.BUTTON1_MASK);
    for (int i = 1; i < pixels; i++) {
      robot.mouseMove(fp.x + frame.getWidth() / 2 + i, fp.y + frame.getHeight() / 2);
    }
    robot.waitForIdle();
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.waitForIdle();

    if (dragged && clicked) {
      throw new RuntimeException(
          "Test failed. Clicked event follows by Dragged. Dragged = "
              + dragged
              + ". Clicked = "
              + clicked
              + " : distance = "
              + pixels);
    }
  }
 @Test
 public void testEntrarComLoginQualquer() {
   try {
     // fail("Not yet implemented");
     try {
       Thread.sleep(3000);
     } catch (Exception e) {
     }
     JButton botaoEntrar = telaLogin.getEntrar();
     Robot r = new Robot();
     r.delay(3000);
     Point p = botaoEntrar.getLocationOnScreen();
     r.mouseMove(p.x + botaoEntrar.getWidth() / 2, p.y + botaoEntrar.getHeight() / 2);
     r.mousePress(InputEvent.BUTTON1_MASK);
     r.delay(3000);
     r.mouseRelease(InputEvent.BUTTON1_MASK);
     r.delay(3000);
   } catch (AWTException exc) {
     exc.printStackTrace();
     fail("awt exception no teste da telaLogin clicar botao entrar");
   }
 }
Ejemplo n.º 30
0
 public void run() {
   BufferedWriter out = null;
   try {
     out = new BufferedWriter(new FileWriter("output"));
   } catch (IOException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
   }
   Robot robot = null;
   try {
     robot = new Robot();
   } catch (AWTException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
   }
   while (true) {
     try {
       int x = in.readInt();
       int y = 1000 - in.readInt() * (-1);
       int clicked = in.readInt();
       if (clicked == YES) {
         robot.mousePress(InputEvent.BUTTON1_MASK);
         System.out.println("YES");
       } else {
         robot.mouseRelease(InputEvent.BUTTON1_MASK);
         System.out.println("NO");
       }
       // apply kalman filter here
       kalmanFilter(x, y); // this would change the values of x2 and y2
       robot.mouseMove((int) x2, (int) y2);
       out.write(x2 + " " + y2 + "\n");
       out.flush();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }