How to debug a TouchAction?

Hello, I am learning to use Appium for a project at work and am hoping to find out if anyone has found any amazing resources for debugging TouchActions. I am using the latest version (Appium v1.7.2), an Android Tablet and the python client. My project has an image that we are rotating and zooming in and out on with touch gestures. These gestures work fine when performed manually, but I haven’t been able to simulate the gestures with the TouchAction and MultiAction.

It would be useful to see something on the screen to indicate that the action actually occurred. There are no error messages and nothing seems to happen on screen. I have been using the Python runtime environment and have my driver and some buttons in a module (f) so I don’t have to retype.

>>> from appium.webdriver.common.touch_action import TouchAction
>>> TouchAction(f.DRIVER).press(x=150, y=150).move_to(x=0, y=350).release().perform()
<appium.webdriver.common.touch_action.TouchAction object at 0x016E48D0>

The Appium Server log looks like this:

[HTTP] --> POST /wd/hub/session/3bf561b0-63d9-46ad-8a13-e21056772dd7/touch/perform {"actions":[{"action":"press","options":{"x":150,"y":150}},{"action":"moveTo","options":{"x":0,"y":350}},{"action":"release","options":{}}],"sessionId":"3bf561b0-63d9-46ad-8a13-e21056772dd7"}
[MJSONWP] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":150,"y":150}},{"action":"moveTo","options":{"x":0,"y":350}},{"action":"release","options":{}}],"3bf561b0-63d9-46ad-8a13-e21056772dd7"]
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchDown","params":{"x":150,"y":150}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":150,"y":150}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchDown
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1280,752]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchDown using element? false x: 150, y: 150
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[AndroidBootstrap] Received command result from bootstrap
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchMove","params":{"x":150,"y":500}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchMove","params":{"x":150,"y":500}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchMove
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1280,752]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchMove using element? false x: 150, y: 500
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[AndroidBootstrap] Received command result from bootstrap
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchUp","params":{"x":150,"y":500}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchUp","params":{"x":150,"y":500}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchUp
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1280,752]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Performing TouchUp using element? false x: 150, y: 500
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.performTouch() result: null
[HTTP] <-- POST /wd/hub/session/3bf561b0-63d9-46ad-8a13-e21056772dd7/touch/perform 200 84 ms - 76 

So it looks like it should have done something. Maybe it has something to do with how fast the gesture happened. I have also tried using the Appium/ApiDemos-debug.apk to draw a smiley face. That works, but the actions happen really fast. Is there a way to slow it down?

It would be great if this worked. I have been looking to see if there are any restrictions or reasons why it doesn’t and have found nothing. Any help would be greatly appreciated.

It was totally the speed of the gesture. I took a look at webdriver.py to see see what commands were available and found that the swipe method is doing exactly what I am doing but passes in a duration in ms.

# convenience method added to Appium (NOT Selenium 3)
def swipe(self, start_x, start_y, end_x, end_y, duration=None):
    """Swipe from one point to another point, for an optional duration.

    :Args:
     - start_x - x-coordinate at which to start
     - start_y - y-coordinate at which to start
     - end_x - x-coordinate at which to stop
     - end_y - y-coordinate at which to stop
     - duration - (optional) time to take the swipe, in ms.

    :Usage:
        driver.swipe(100, 100, 100, 400)
    """
    # `swipe` is something like press-wait-move_to-release, which the server
    # will translate into the correct action
    action = TouchAction(self)
    action \
        .press(x=start_x, y=start_y) \
        .wait(ms=duration) \
        .move_to(x=end_x, y=end_y) \
        .release()
    action.perform()
    return self

I added a couple of seconds to my TouchAction and it works wonderfully.

Hopefully this will help someone running into the same issue.

@ChrisS with Android in developer options enable - show touches and show touch data. You will see now visually you touches.

1 Like