小弟最近在研究图案解锁,想利用多点触控来解决问题,但是实际过程中发现一个奇怪的问题,待小弟慢慢说来。
JAVA CLIENT 版本 3.0.0
JAVA 调用代码如下
final TouchAction gesture = new TouchAction((MobileDriver) driver)
.press(point0.getX(), point0.getY())
.moveTo(point1.getX(), point1.getY())
.moveTo(point2.getX(), point2.getY())
.moveTo(point3.getX(), point3.getY()).release();
gesture.perform();
实际上给出的 4 个点坐标值分别为:
(226, 756)
(226, 1071)
(226, 1386)
(539, 1386)
查看 appium debug log 发现:
> info: --> POST /wd/hub/session/92bcec80-2500-40a3-ae79-2223d4cd17dd/touch/perform {"actions":[{"action":"press","options":{"x":226,"y":756}},{"action":"moveTo","options":{"x":226,"y":1071}},{"action":"moveTo","options":{"x":226,"y":1386}},{"action":"moveTo","options":{"x":539,"y":1386}},{"action":"release","options":{}}]}
> info: [debug] Pushing command to appium work queue: ["element:touchDown",{"x":226,"y":756}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":226,"y":756}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: touchDown
> info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][1080,1776]
> info: [debug] [BOOTSTRAP] [debug] Performing TouchDown using element? false x: 226, y: 756
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Pushing command to appium work queue: ["element:touchMove",{"x":452,"y":1827}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchMove","params":{"x":452,"y":1827}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: touchMove
> info: [debug] Responding to client with error: {"status":29,"value":{"message":"The coordinates provided to an interactions operation are invalid.","origValue":"Coordinate [x=452.0, y=1827.0] is outside of element rect: [0,0][1080,1776]"},"sessionId":"92bcec80-2500-40a3-ae79-2223d4cd17dd"}
发送的请求是正确的,第一个点也能正确点击到,第二点的 moveTo 的坐标居然变成了: ["element:touchMove",{"x":452,"y":1827}] 有木有啊。。。
仔细一看,发现是把 moveTo 的坐标值跟第一次 press 的坐标值相加之后得到的结果,导致超出了坐标系,报了个错
org.openqa.selenium.interactions.InvalidCoordinatesException: The coordinates provided to an interactions operation are invalid. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 45 milliseconds
尝试第二种方法:MultiTouchAction
MultiTouchAction multiTouchAction = new MultiTouchAction((MobileDriver) driver);
TouchAction action0 = new TouchAction((MobileDriver) driver).press(point0.getX(), point0.getY());
TouchAction action1 = new TouchAction((MobileDriver) driver).moveTo(point0.getX(), point0.getY());
TouchAction action2 = new TouchAction((MobileDriver) driver).moveTo(point0.getX(), point0.getY());
TouchAction action3 = new TouchAction((MobileDriver) driver).moveTo(point0.getX(), point0.getY()).release();
multiTouchAction.add(action0).add(action1).add(action2).add(action3).perform();
appium debug log:
> info: --> POST /wd/hub/session/59049042-efab-4b94-be86-546f14138a93/touch/multi/perform {"actions":[[{"action":"press","options":{"x":226,"y":756}}],[{"action":"moveTo","options":{"x":226,"y":756}}],[{"action":"moveTo","options":{"x":226,"y":756}}],[{"action":"moveTo","options":{"x":226,"y":756}},{"action":"release","options":{}}]]}
> info: [debug] Pushing command to appium work queue: ["performMultiPointerGesture",{"actions":[[{"action":"press","time":0.005,"touch":{"x":226,"y":756}}],[{"action":"moveTo","time":0.005,"touch":{"x":226,"y":756}}],[{"action":"moveTo","time":0.005,"touch":{"x":226,"y":756}}],[{"action":"moveTo","time":0.005,"touch":{"x":226,"y":756}}]]}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"performMultiPointerGesture","params":{"actions":[[{"action":"press","time":0.005,"touch":{"x":226,"y":756}}],[{"action":"moveTo","time":0.005,"touch":{"x":226,"y":756}}],[{"action":"moveTo","time":0.005,"touch":{"x":226,"y":756}}],[{"action":"moveTo","time":0.005,"touch":{"x":226,"y":756}}]]}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: performMultiPointerGesture
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK","status":0}
> info: [debug] Responding to client with success: {"status":0,"value":"OK","sessionId":"59049042-efab-4b94-be86-546f14138a93"}
> info: <-- POST /wd/hub/session/59049042-efab-4b94-be86-546f14138a93/touch/multi/perform 200 137.629 ms - 76 {"status":0,"value":"OK","sessionId":"59049042-efab-4b94-be86-546f14138a93"}
> info: --> POST /wd/hub/session/59049042-efab-4b94-be86-546f14138a93/touch/perform {"actions":[{"action":"press","options":{"x":226,"y":756}},{"action":"moveTo","options":{"x":226,"y":1071}},{"action":"moveTo","options":{"x":226,"y":1386}},{"action":"moveTo","options":{"x":539,"y":1386}},{"action":"release","options":{}}]}
> info: [debug] Pushing command to appium work queue: ["element:touchDown",{"x":226,"y":756}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":226,"y":756}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: touchDown
> info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][1080,1776]
> info: [debug] [BOOTSTRAP] [debug] Performing TouchDown using element? false x: 226, y: 756
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Pushing command to appium work queue: ["element:touchMove",{"x":452,"y":1827}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchMove","params":{"x":452,"y":1827}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: touchMove
> info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][1080,1776]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Coordinate [x=452.0, y=1827.0] is outside of element rect: [0,0][1080,1776]","status":29}
> info: [debug] Responding to client with error: {"status":29,"value":{"message":"The coordinates provided to an interactions operation are invalid.","origValue":"Coordinate [x=452.0, y=1827.0] is outside of element rect: [0,0]
出现了同样的问题,发送的指令看似正确,但是执行的时候却错误了。。。T_T
求大神指教。。@monkey @chenhengjie123