macaca icon indicating copy to clipboard operation
macaca copied to clipboard

移动端支持手势识别

Open xudafeng opened this issue 9 years ago • 36 comments

6 gestures supported

Type Params Example Description
tap { x: 100, y: 100 } driver.touch('tap', { x: 100, y: 100}) | element.touch('tap') 点击某个坐标或者当前元素
doubleTap { x: 100, y: 100 } driver.touch('doubleTap', { x: 100, y: 100}) | element.touch('doubleTap') 双击某个坐标或者当前元素
press { x: 100, y: 100,duration: 2 (iOS,单位 S), steps: 100(Android) } driver.touch('press', { x: 100, y: 100}) | element.touch('press', { duration: 2 }) 长按某个坐标或者当前元素
pinch { x: 100, y: 100,scale: 2 (iOS), velocity: 1(iOS), direction: "in" or "out"(Android), percent: 200(Android), steps: 100(Android) } iOS: element.touch('pinch', { scale: 2 }), Android: element.touch('pinch', { direction: "in", percent: 50 }) 两只手指放大或者缩小当前元素
rotate (iOS Only) { rotation: 6(弧度), velocity: 1 } element.touch('rotate', { rotation: 6, velocity: 1 }) 旋转当前元素
drag { fromX: 100, fromY: 100, toX: 200, toY: 200, duration: 2(iOS,单位 S), steps: 100(Android)} driver.touch('drag', { fromX: 100, fromY: 100, toX: 200, toY: 200 }) | element.touch('drag', { toX: 200, toY: 200 }) 拖拽一个元素或者在多个坐标之间移动

高级用法

连续执行多个 touch 操作,类似于下图的密码解锁。

driver.touch([{
  type: 'drag',
  fromX: 265,
  fromY: 860,
  toX: 825,
  toY: 860,
  steps: 200
}, {
  type: 'drag',
  toX: 265,
  toY: 1460
}, {
  type: 'drag',
  toX: 825,
  toY: 1460
}])

touch-gestures

1

xudafeng avatar Dec 13 '16 05:12 xudafeng

https://github.com/alibaba/macaca/issues/198

xudafeng avatar Dec 13 '16 05:12 xudafeng

https://github.com/xudafeng/android-app-bootstrap/pull/7

xudafeng avatar Dec 13 '16 05:12 xudafeng

https://github.com/xudafeng/ios-app-bootstrap/pull/15

xudafeng avatar Dec 13 '16 05:12 xudafeng

https://github.com/macacajs/wd.java/pull/67

xudafeng avatar Dec 13 '16 05:12 xudafeng

https://github.com/macacajs/wd.py/commit/74a109a4194196f410103456395e701e2fe51e7c

xudafeng avatar Dec 13 '16 05:12 xudafeng

https://github.com/macacajs/wd.py/commit/74a109a4194196f410103456395e701e2fe51e7c

xudafeng avatar Dec 13 '16 05:12 xudafeng

https://github.com/alibaba/macaca/issues/231

xudafeng avatar Dec 13 '16 05:12 xudafeng

https://github.com/macacajs/uiautomator-client/pull/28

xudafeng avatar Dec 13 '16 06:12 xudafeng

https://github.com/macacajs/macaca-android/pull/46

xudafeng avatar Dec 13 '16 06:12 xudafeng

tap像素的需求很迫切呀

CodeToSurvive1 avatar Dec 13 '16 07:12 CodeToSurvive1

@zenzhu 本次新增功能会实现的 @CodeToSurvive1

xudafeng avatar Dec 13 '16 07:12 xudafeng

https://github.com/alibaba/macaca/issues/374

xudafeng avatar Dec 14 '16 09:12 xudafeng

@xudafeng ,Is the functionality done? If so, can you please provide an example in JS on how to do swipe action? Swipe works fine in my local machine but when executed in saucelabs, I get an error that The URL '/wd/hub/session/84eae9c3-2df1-426c-a81c-adc7f0b1a3e4/element/370/swipe' did not map to a valid resource

mpreethi90 avatar Dec 15 '16 01:12 mpreethi90

https://github.com/macaca-sample/macaca-test-sample-nodejs/commit/8bab04bafb174d2fddacb83b837ba8da0f6afe5a

xudafeng avatar Dec 15 '16 10:12 xudafeng

https://testerhome.com/topics/6722

xudafeng avatar Dec 15 '16 10:12 xudafeng

@xudafeng 达峰麻烦解释一下: 1.标准有(Android)或(iOS)的是否该参数只能在对应平台使用? 实验结果:drag可以在Android平台使用duration参数。 2.pinch的用法。 { x: 100, y: 100,scale: 2 (iOS), velocity: 1(iOS), direction: "in" or "out"(Android), percent: 200(Android), steps: 100(Android) } 如果iOS用scale+velocity,Android使用direction+percent+steps?

adfghzhang avatar Jan 07 '17 10:01 adfghzhang

@xudafeng 遇到的问题: IOS上,手势解锁操作中使用driver.touch()方法来实现‘先横后竖’的操作,但是执行时,并没有一步完成,而是连续的操作被分成两步操作分别进行的。请问是否支持ios?还是使用方法不对?

macaca版本:1.1.21 ios driver:1.0.53 手机:iPhone 6s 9.3.1 OS:10.11.6 node:v4.6.2

源码:

driver.touch([
      {
        type: 'drag',
        fromX: 85,
        fromY: 312,
        toX: 281,
        toY: 312,
        duration:0.2
      },
      {
        type: 'drag',
        toX: 281,
        toY: 505
      }
    ]);

macaca server 日志:

>> responseHandler.js:11:12 [master] pid:77978 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/aa2ec7ef-7bf4-45c4-a46f-fd50ed20b523/actions, jsonBody: {"actions":[{"type":"drag","fromX":85,"fromY":312,"toX":281,"toY":312,"duration":0.2},{"type":"drag","toX":281,"toY":505}]}
>> proxy.js:56:14 [master] pid:77978 Proxy: /wd/hub/session/temp/dragfromtoforduration:POST to http://127.0.0.1:8900/session/47B7256E-7C1E-433A-A050-9B3BC40C4EE3/dragfromtoforduration:POST with body: {"fromX":85,"fromY":312,"toX":281,"toY":312,"duration":0.2}
>> proxy.js:84:20 [master] pid:77978 Got response with status 200: {"value":{},"sessionId":"temp","status":0}
>> proxy.js:56:14 [master] pid:77978 Proxy: /wd/hub/session/temp/dragfromtoforduration:POST to http://127.0.0.1:8900/session/47B7256E-7C1E-433A-A050-9B3BC40C4EE3/dragfromtoforduration:POST with body: {"toX":281,"toY":505,"duration":1}
>> proxy.js:84:20 [master] pid:77978 Got response with status 200: {"value":{},"sessionId":"temp","status":0}
>> responseHandler.js:47:14 [master] pid:77978 Send HTTP Respone to Client: {"sessionId":"aa2ec7ef-7bf4-45c4-a46f-fd50ed20b523","status":0,"value":null}

qq386169040 avatar Feb 13 '17 07:02 qq386169040

@qq386169040 iOS 原生就不支持这种手势操作,暂时只有安卓支持。

ziczhu avatar Feb 14 '17 02:02 ziczhu

@zenzhu 谢谢你的解答

qq386169040 avatar Feb 16 '17 03:02 qq386169040

@xudafeng 求ios手势密码的解决方案,试过@qq386169040 的方法也试过连续tap,,好像都实现不了,, 另外想问一下touch方法在ios的坐标系是以哪个地方作为起点的,感觉每次定位都不准,用app-inspector给出的x,y参数都不怎么准确

ElesG avatar Feb 28 '17 13:02 ElesG