appium/appium-android-driver

Support touch actions that don't start with press

tiagoshibata opened this issue · 1 comments

Hi all! I have one more request for a fix on touch actions.

The problem

For some specific tests I'd like to be able to start a drag action and then zoom in the screen (start with a single finger and later touch another finger). The following Python code exemplifies my desired behavior:

#!/usr/bin/env python3
import appium
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.multi_action import MultiAction

capabilities = {
    'appActivity': "<activity>",
    'appPackage': "<package>",
    'deviceName': "Android",
    'platformName': "Android",
    'noReset': False
}

webdriver = appium.webdriver.Remote("http://localhost:4723/wd/hub", capabilities)
try:
    contact_1 = TouchAction(webdriver).press(x=14, y=14).wait(5).move_to(x=5, y=-5).release()
    contact_2 = TouchAction(webdriver).wait(5).press(x=24, y=24).wait(5).move_to(x=0, y=4).release()
    multi_touch = MultiAction(webdriver)
    multi_touch.add(contact_1)
    multi_touch.add(contact_2)
    multi_touch.perform()
finally:
    webdriver.quit()

However, Appium crashes when the touch action doesn't start with a press checking the yet undefined x/y coordinates. In the example above, it crashes on the second contact, which starts with wait.

Environment

  • Appium version (or git revision) that exhibits the issue: e026a14141230416e945fb6b49883b9993833f31
  • Desktop OS/version used to run Appium: Linux
  • Node.js version: v6.3.0
  • Mobile platform/version under test: Android
  • Real device
  • Appium CLI

Link to Appium logs

Here, relevant parts:

[HTTP] --> POST /wd/hub/session/52783d80-5081-4bcc-8c45-4b8ca858a159/touch/multi/perform {"sessionId":"52783d80-5081-4bcc-8c45-4b8ca858a159","actions":[[{"action":"press","options":{"x":14,"y":14}},{"action":"moveTo","options":{"x":5,"y":-5}},{"action":"release","options":{}}],[{"action":"wait","options":{"ms":5}},{"action":"press","options":{"x":24,"y":24}},{"action":"moveTo","options":{"x":0,"y":4}},{"action":"release","options":{}}]]}
[MJSONWP] Calling AppiumDriver.performMultiAction() with args: [[[{"action":"press","optio...
[MJSONWP] Encountered internal error running command: TypeError: Cannot read property 'x' of null
    at AndroidDriver.callee$0$0$ (lib/commands/touch.js:258:32)
    at tryCatch (/home/tiago/code/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/home/tiago/code/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/home/tiago/code/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/home/tiago/code/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)

Code To Reproduce Issue

Given above.


Could some of you provide a fix? I might try to get a PR done if you guys are busy with other issues.

Thanks!

Seems easy to fix, I will get a PR with tests against this bug and a fix done tomorrow.