0

I'm writing auto-tests for an openLayers web application (similar to Google Maps), trying to get it to click and drag to pan the map, as any user normally would. After many attempts and research, I still cannot get it to pan automagically. This is using a Chrome driver.

My code seems correct because I tried starting the tests, then quickly switching to a notepad window full of text, and voila, the text gets highlighted.

Robot robot = new Robot()
robot.mouseMove(501,501) // starting cursor position, somewhere near the middle of the map
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK)
// robot.delay(1000) // tried this but it made no difference
Thread.sleep(1000)
robot.mouseMove(400,400) // another position, still within the map's frame
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK)

Expected results: map pans

Actual results: cursor jumps location but the map does not move

No error messages

Update: If I move the mouse cursor slightly over the map whist the test is running, the panning occurs as expected.

Stuart
  • 41
  • 3

1 Answers1

0

Meanwhile I may have found the answer to my own question.

The speed of the cursor may have just been too fast for my map application so I put the mouseMove() method inside of a loop, whereby with each iteration the x and y position increases or decreases by one pixel. Also added a robot.delay(5) at the end. The result looks like a smooth mouse movement. Here is a snippet:

int pixX = 499
int pixY = 499

robot.mouseMove(500, 500) // Setting cursor starting position
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK)
robot.delay(500)

    while(pixX > 450 && pixY > 450) {
        robot.mouseMove(pixX, pixY)
        pixX--
        pixY--
        robot.delay(5)
    }
robot.delay(100) // Short delay at the end before releasing mouse button
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK)
Stuart
  • 41
  • 3