Java-client: touchAction: longPress, moveTo, waitAction, release - doesn't work

Created on 23 Feb 2018  路  15Comments  路  Source: appium/java-client

Description

I need to implement following gesture.
Press on some element on the screen, move it to another element, waiting for 5 seconds and release it.

Trying to use below touchAction:
TouchAction touchAction = new TouchAction((AndroidDriver) driver); touchAction.longPress(FirstElement).moveTo(TwoElement.getCenter().x, TwoElement.getCenter().y).waitAction(Duration.ofMillis(15000)).release().perform();
But it doesn't work. Nothing happens on the screen.

Environment

  • java client build version: 5.0.0-BETA9
  • Appium server: 1.7.1
  • Desktop OS/version used to run Appium if necessary: macOS 10.13.3
  • Mobile platform/version under test: Nexus 5X API 24, 7.0
  • Real device or emulator/simulator: emulator

Details

If I use below touch action:
touchAction.longPress(FirstElement, Duration.ofMillis(15000)).moveTo(TwoElement.getCenter().x, TwoElement.getCenter().y).release().perform();

I see that required element is moving on the page, but it doesn't wait before releasing.

Code To Reproduce Issue

TouchAction touchAction = new TouchAction((AndroidDriver) driver); touchAction.longPress(FirstElement).moveTo(TwoElement.getCenter().x, TwoElement.getCenter().y).waitAction(Duration.ofMillis(15000)).release().perform();

Link to Appium logs

https://gist.github.com/aozolin/86f7bba13f6951a5a0cf671a5c131485

server side

Most helpful comment

In case anyone else has a similar problem and can't find a working solution, check out this post on SO.

All 15 comments

@aozolin Please use Dimension to get the position of the element, getCenter() is getting from center of the screen and not respective to element.

java client build version: 6.0.0-BETA2

new TouchAction(driver).press(ElementOption.element(dragMe,dragMe.getSize().getWidth() / 2,dragMe.getSize().getHeight() / 2))
                .moveTo(ElementOption.element(dropzone,dropzone.getSize().getWidth() / 2
                        ,dragMe.getSize().getHeight() / 2)).release().perform();

@saikrishna321 Thanks. I've updated my client to the latest version, and reimplement my touch action using new methods as your recommendation. And it doesn't work.

As I see, my waitingAction after moveTo step is executed before any actions.
So it waits specified time, and than moves to coordinates and releases touch immediately, but I'm expecting to wait between moveTo and release actions.

Can you please provide the latest logs

@saikrishna321,
The code is:
PointOption pointOptionB = new PointOption(); pointOptionB.withCoordinates(finishX / 2, finishY / 2); new TouchAction(driver).press(ElementOption.element(FirstElement,FirstElement.getSize().getWidth() / 2,FirstElement.getSize().getHeight() / 2)) .moveTo(pointOptionB).waitAction(new WaitOptions().withDuration(Duration.ofSeconds(5))).release().perform();

Please see logs from appium server:
https://gist.github.com/aozolin/169e78dcf4cedfac3c385dab8c3bcd5b

As I see on the screen, it waits for 5 seconds and then perform all actions immediate.
As if I move element to required coordinates and hold it for a few seconds, context menu will appear. But it's not.

@aozolin I suspect it's a server bug and its how it was designed earlier i believe.

@SrinivasanTarget, I think so. In this case can you fix it?

@imurchie @mykola-mokhnach Any thoughts?

@imurchie @mykola-mokhnach, please advise how to solve the issue.

I have the same problem with appium 1.8 and java-client 6 beta 2. below is appium logs

[HTTP] {"actions":[{"action":"longPress","options":{"x":918,"y":538}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":162,"y":538}},{"action":"release","options":{}}]}
[debug] [W3C] Calling AppiumDriver.performTouch() with args: [[{"action":"longPress","options":{"x":918,"y":538}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":162,"y":538}},{"action":"release","options":{}}],"2dc37473-8dc3-4452-9e4f-0ab7df4192ce"]
[debug] [JSONWP Proxy] Proxying [POST /touch/down] to [POST http://localhost:8200/wd/hub/session/1bab9843-1d2a-40c4-af8b-32d5d6aa2e67/touch/down] with body: {"params":{"x":918,"y":538}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"1bab9843-1d2a-40c4-af8b-32d5d6aa2e67","status":0,"value":true}
[debug] [JSONWP Proxy] Proxying [POST /touch/move] to [POST http://localhost:8200/wd/hub/session/1bab9843-1d2a-40c4-af8b-32d5d6aa2e67/touch/move] with body: {"params":{"x":162,"y":538}}
[W3C] Encountered internal error running command: {"w3cStatus":400,"jsonwp":{"sessionId":"1bab9843-1d2a-40c4-af8b-32d5d6aa2e67","status":13,"value":false}} ProxyRequestError: Could not proxy command to remote server. Original error: 500 - {"sessionId":"1bab9843-1d2a-40c4-af8b-32d5d6aa2e67","status":13,"value":false}
[W3C] at JWProxy.proxy$ (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:152:13)
[W3C] at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
[W3C] at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
[W3C] at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
[W3C] at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[W3C] at
[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError
[HTTP] <-- POST /wd/hub/session/2dc37473-8dc3-4452-9e4f-0ab7df4192ce/touch/perform 500 3425 ms - 1194

Currently having the same issue with appium not scrolling or 'MoveTo' elements.
The current code won't scroll to the element. All it does is pass as if it did 'Something'. No error message or failure log.

public void scrollToItem(String sheetName, String valueName, String valuName2) throws IOException {

    // Locate the element to scroll to
    WebElement fromElement = myPage.getElement(sheetName, valueName, 5);
    WebElement toElement = myPage.getElement(sheetName, valuName2, 5);
    TouchAction tAction = new TouchAction(driver);
    tAction.press(fromElement).moveTo(toElement).release().perform();

}

The issue I am also facing is the fact that I can't scroll until an element is visible. This option is very desirable.

Appium java client - 6.0.0
Appium server - 1.8.1
Mac os high sierra
IntelliJ IDE

@Garreth210 You are missing the waitAction.

new TouchAction(driver).press(ElementOption.element(element1))
.waitAction(WaitOptions.waitOptions(Duration.ofSeconds(3))).moveTo(ElementOption.element(element2)).release().perform();    

In case anyone else has a similar problem and can't find a working solution, check out this post on SO.

Facing the same issue with latest java-client 6.1.0. TouchAction not working with AppiumDriver(driver). I am working on webview elements. Advise the way around this if you have any..

As latest java-client has deprecated use of most of Actions class implemented function, looking for a solution..

@jlipps @saikrishna321 for a solution

Was this page helpful?
0 / 5 - 0 ratings