Java-клиент iOS + appium: длительное нажатие TouchAction не работает?

Я пытаюсь автоматизировать действие касания при длительном нажатии в родном приложении iOS.

Подход 1: имитировать долгое нажатие в верхнем левом углу, что не сработало.

new TouchAction(driver).longPress(0,0).perform() Журналы Appium не показывают ошибок:

info: [debug] [INST] 2015-12-21 17:41:19 +0000 Debug: Got new command 5 from instruments: target.touch([{"touch":[{"x":0,"y":0}],"time":0.2}])
info: [debug] [INST] 2015-12-21 17:41:19 +0000 Debug: evaluating target.touch([{"touch":[{"x":0,"y":0}],"time":0.2}])
info: [debug] [INST] 2015-12-21 17:41:19 +0000 Debug: target.touch(__NSCFArray)
info: [debug] [INST] 2015-12-21 17:41:20 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-12-21 17:41:20 +0000 Debug: responding with:
info: [debug] [INST] 2015-12-21 17:41:20 +0000 Debug: Running system command #6: /usr/local/Cellar/node/4.1.1/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
info: [debug] Socket data received (25 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":""}
info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"332523ee-5a1b-427a-8beb-3c150587d08b"}

Подход 2: выполнить javascript для имитации длительного нажатия

((IOSDriver)driver).executeScript("mobile: longClick", ImmutableMap.of("x", 5, "y", 5));

Исключение журнала Appium выглядит следующим образом:

TypeError: cb is not a function
    at [object Object].iOSController.touchLongClick (/usr/local/lib/node_modules/appium/lib/devices/ios/ios-controller.js:614:3)
    at Object.exports.touchLongClick [as longClick] (/usr/local/lib/node_modules/appium/lib/server/controller.js:371:16)
    at Object.exports.executeMobileMethod (/usr/local/lib/node_modules/appium/lib/server/controller.js:984:22)
    at exports.execute (/usr/local/lib/node_modules/appium/lib/server/controller.js:940:15)
    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:82:5)

person Utkarsha Padhye    schedule 21.12.2015    source источник
comment
Также возможно, что характер веб-элемента изменяется после нажатия, а время ожидания истекает... попробуйте долгое нажатие с координатами.   -  person the_prole    schedule 07.06.2018


Ответы (2)


Вы должны передать 2 аргумента методам longPress(). Это элемент (элемент в приведенном ниже коде), который вы хотите удерживать, и время (2000 мс), сколько времени он должен удерживать.

MobileElement element = driver.findElementByClassName("xxx");
new TouchAction(driver).longPress(element, 2000).perform();
person Shiva krishna Chippa    schedule 29.12.2015

Замените new TouchAction(driver).longPress(0,0).perform() на

TouchAction action = new TouchAction(driver).longPress(0,0).release();

action.perform();

Убедитесь, что у вас есть правильные координаты.

person Gaurav    schedule 22.12.2015