Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robot fails to click on Mac OS X / Java 7 #19

Open
caillette opened this issue Jun 6, 2013 · 0 comments
Open

Robot fails to click on Mac OS X / Java 7 #19

caillette opened this issue Jun 6, 2013 · 0 comments

Comments

@caillette
Copy link

When running tests on Mac OS X (10.8.4) and Java 7 (1.7.0_21-b12) the mouse pointer jitters over text fields and takes dozens of seconds before it finally clicks on them. The tests don't really fail but become slow enough to prevent from building.

Emmanuel Puybaret (author of 2 books on Java) found the following workaround. The System property resolution should go in a constant but we favored readability.

org.fest.swing.monitor.WindowStatus

@RunsInEDT
private void mouseMove(final Window w, Point point) {
  final int x = point.x;
  final int y = point.y;
  if (x == 0 || y == 0) return;
  robot.mouseMove(x, y);
  // ************************
  // EP : Dispatch missing MouseEvent under Mac OS X / Java 7
  if (System.getProperty("os.name").startsWith("Mac OS X")
      && System.getProperty("java.version").startsWith("1.7")
      && w.isShowing()
      && w.getBounds().contains(x, y)) {
    java.awt.EventQueue.invokeLater(new Runnable() {
         @Override
         public void run() {
           w.dispatchEvent(new java.awt.event.MouseEvent(w, java.awt.event.MouseEvent.MOUSE_MOVED,
                System.currentTimeMillis(), 0, x - w.getX(), y - w.getY(), x, y, 0, false, 0));
         }
       });
  }
  // EP : End of modification
  // ************************
  Dimension windowSize = sizeOf(w);
  if (windowSize.width > windowSize.height) robot.mouseMove(x + sign, y);
  else robot.mouseMove(x, y + sign);
  sign = -sign;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant