我正在为一个openLayers网络应用程序编写自动测试(类似于Google ),试图让它点击并拖动到地图上,就像任何用户通常所做的那样。经过多次的尝试和研究,我仍然无法自动地将其应用于pan。这是使用Chrome驱动程序。
我的代码似乎是正确的,因为我试着开始测试,然后快速切换到一个充满文本的记事本窗口,而瞧,文本会被高亮显示。
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)预期结果: map pans
实际结果:光标跳转位置,但地图不移动
没有错误消息
Update:如果我将鼠标光标移动到正在运行测试的地图上,则按预期进行摇摄。
发布于 2019-08-06 08:07:06
与此同时,我可能已经找到了我自己问题的答案。
对于我的地图应用程序来说,光标的速度可能太快了,所以我将mouseMove()方法放在循环中,这样每次迭代时x和y的位置增加或减少一个像素。最后还添加了一个robot.delay(5)。结果看上去像滑鼠平稳的移动。下面是一个片段:
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)https://stackoverflow.com/questions/57364011
复制相似问题