appium / appium-uiautomator2-server

Appium UiAutomator/UiObject2-based server for Android UI automation. This module is used by appium-uiautomator2-driver component
Apache License 2.0
331 stars 233 forks source link

"Swipe by coordinates" doesn't work #229

Open Ma2ter opened 5 years ago

Ma2ter commented 5 years ago

Appium version: 1.11.0-beta.0 (same with appium 1.9.1 and 1.10) Following code doesn't work:

protected void swipe(int startX, int startY, int endX, int endY) {
        new TouchAction(driver).press(PointOption.point(startX, startY))
                .waitAction(WaitOptions.waitOptions(Duration.ofMillis(3000)))
                .moveTo(PointOption.point(endX, endY))
                .waitAction(WaitOptions.waitOptions(Duration.ofMillis(3000)))
                .release().perform();
    }

if start point hits on the layout element (android.widget.LinearLayout, android.widget.RelativeLayout) . However, if startPoint hits empty space on the screen, scroll is successful.

It completes successfully, but nothing changes on the screen.

[HTTP] --> POST /wd/hub/session/763f8f44-ced4-4730-98a6-eaaa35bb6748/touch/perform
[HTTP] {"actions":[{"action":"press","options":{"x":540,"y":1536}},{"action":"wait","options":{"ms":3000}},{"action":"moveTo","options":{"x":540,"y":384}},{"action":"wait","options":{"ms":3000}},{"action":"release","options":{}}]}
[debug] [W3C] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":540,"y":1536}},{"action":"wait","options":{"ms":3000}},{"action":"moveTo","options":{"x":540,"y":384}},{"action":"wait","options":{"ms":3000}},{"action":"release","options":{}}],"763f8f44-ced4-4730-98a6-eaaa35bb6748"]
[debug] [JSONWP Proxy] Matched '/touch/down' to command name 'touchDown'
[debug] [JSONWP Proxy] Proxying [POST /touch/down] to [POST http://localhost:8202/wd/hub/session/d4adaf44-692a-46f8-8bb0-0d6f696a5438/touch/down] with body: {"params":{"x":540,"y":1536}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"d4adaf44-692a-46f8-8bb0-0d6f696a5438","status":0,"value":true}
[debug] [JSONWP Proxy] Matched '/touch/move' to command name 'touchMove'
[debug] [JSONWP Proxy] Proxying [POST /touch/move] to [POST http://localhost:8202/wd/hub/session/d4adaf44-692a-46f8-8bb0-0d6f696a5438/touch/move] with body: {"params":{"x":540,"y":384}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"d4adaf44-692a-46f8-8bb0-0d6f696a5438","status":0,"value":true}
[debug] [JSONWP Proxy] Matched '/touch/up' to command name 'touchUp'
[debug] [JSONWP Proxy] Proxying [POST /touch/up] to [POST http://localhost:8202/wd/hub/session/d4adaf44-692a-46f8-8bb0-0d6f696a5438/touch/up] with body: {"params":{"x":540,"y":384}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"d4adaf44-692a-46f8-8bb0-0d6f696a5438","status":0,"value":true}
[debug] [W3C] Responding to client with driver.performTouch() result: null
[HTTP] <-- POST /wd/hub/session/763f8f44-ced4-4730-98a6-eaaa35bb6748/touch/perform 200 8388 ms - 14

Same happening when trying perform "Swipe by coordinates" in appium-desktop.

[HTTP] {"actions":[{"action":"press","options":{"x":724,"y":1514}},{"action":"moveTo","options":{"x":693,"y":875}},{"action":"release","options":{}}]}
[MJSONWP (35565ad3)] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":724,"y":1514}},{"action":"moveTo","options":{"x":693,"y":875}},{"action":"release","options":{}}],"35565ad3-b5d9-424b-941f-f9cb70cfd568"]
[JSONWP Proxy] Matched '/touch/down' to command name 'touchDown'
[JSONWP Proxy] Proxying [POST /touch/down] to [POST http://localhost:8202/wd/hub/session/db0591d7-2082-4c0b-8ef0-46245c254f1e/touch/down] with body: {"params":{"x":724,"y":1514}}
[JSONWP Proxy] Got response with status 200: {"sessionId":"db0591d7-2082-4c0b-8ef0-46245c254f1e","status":0,"value":true}
[JSONWP Proxy] Matched '/touch/move' to command name 'touchMove'
[JSONWP Proxy] Proxying [POST /touch/move] to [POST http://localhost:8202/wd/hub/session/db0591d7-2082-4c0b-8ef0-46245c254f1e/touch/move] with body: {"params":{"x":693,"y":875}}
[JSONWP Proxy] Got response with status 200: {"sessionId":"db0591d7-2082-4c0b-8ef0-46245c254f1e","status":0,"value":true}
[JSONWP Proxy] Matched '/touch/up' to command name 'touchUp'
[JSONWP Proxy] Proxying [POST /touch/up] to [POST http://localhost:8202/wd/hub/session/db0591d7-2082-4c0b-8ef0-46245c254f1e/touch/up] with body: {"params":{"x":693,"y":875}}
[JSONWP Proxy] Got response with status 200: {"sessionId":"db0591d7-2082-4c0b-8ef0-46245c254f1e","status":0,"value":true}
[MJSONWP (35565ad3)] Responding to client with driver.performTouch() result: null
[HTTP] <-- POST /wd/hub/session/35565ad3-b5d9-424b-941f-f9cb70cfd568/touch/perform

Capabilities:

{
  "platformName": "Android",
  "automationName": "UIAutomator2",
  "deviceName": "Redmi Note 4",
  "app": "<path>/app/Android.apk"
}
jlipps commented 5 years ago

Can you try the W3C action API instead of the old TouchAction API?

Ma2ter commented 5 years ago

W3C actions works fine, thank you!

Also, I solved the problem with following code:

new TouchAction(driver).longPress(PointOption.point(startX, startY))
                    .moveTo(PointOption.point(endX, endY))
                    .release().perform();
wesley-firewalla commented 5 years ago

W3C actions works fine, thank you!

Also, I solved the problem with following code:

new TouchAction(driver).longPress(PointOption.point(startX, startY))
                    .moveTo(PointOption.point(endX, endY))
                    .release().perform();

yes, change the press to longPress fixed the issue. @jlipps Can you update the appium-desktop, it is still generating the old code.