Java-client: swipe not act as expected

Created on 29 Mar 2016  路  20Comments  路  Source: appium/java-client

Description

trying to use element.swipe(UP, duration);, but the undergoing swipe(int startx, int starty, int endx, int endy, int duration) does not work as expected

Environment

  • java client build version or git revision if you use some shapshot: 3.4.0
  • Appium server version or git revision if you use some shapshot: 1.5.0
  • Desktop OS/version used to run Appium if necessary: Mac OSX 10.11
  • Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe: 5.6.0
  • Mobile platform/version under test: iPhone 9.2.1
  • Real device or emulator/simulator: 6s plus

    Details

I was trying to do element.swipe(UP, duration).
According to the debug level logs, after some getLocation and getSize requests , appium called swipe(int, int,int,int,int) as below:

[MJSONWP] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":207,"y":439}},{"action":"wait","options":{"ms":1000}},{"action":"moveTo","options":{"x":207,"y":298}},{"action":...

it was a correct swipe up action. but following logs showed that it interpreted the actions wrong to following commands:

[debug] [iOS] Executing iOS command 'performTouch'
[debug] [UIAuto] Sending command to instruments: target.touch([{"touch":[{"x":207,"y":439}],"time":0.2},{"touch":[{"x":207,"y":439}],"time":1.2},{"touch":[{"x":414,"y":737}],"time":1.4}])
[debug] [Instruments] [INST] 2016-03-29 08:44:34 +0000 Debug: Got new command 18 from instruments: target.touch([{"touch":[{"x":207,"y":439}],"time":0.2},{"touch":[{"x":207,"y":439}],"time":1.2},{"touch":[{"x":414,"y":737}],"time":1.4}])
[debug] [Instruments] [INST] 2016-03-29 08:44:34 +0000 Debug: evaluating target.touch([{"touch":[{"x":207,"y":439}],"time":0.2},{"touch":[{"x":207,"y":439}],"time":1.2},{"touch":[{"x":414,"y":737}],"time":1.4}])
[debug] [Instruments] [INST] 2016-03-29 08:44:34 +0000 Debug: target.touch(__NSCFArray)
[debug] [Instruments] [INST] 2016-03-29 08:44:35 +0000 Debug: point is not within the bounds of the screen
[debug] [UIAuto] Socket data received (70 bytes)
[debug] [UIAuto] Got result from instruments: {"status":17,"value":"point is not within the bounds of the screen"}
[HTTP] <-- POST /wd/hub/session/47695b97-9182-4258-a23b-a0f478210510/touch/perform 500 1763 ms - 131
[debug] [Instruments] [INST] 2016-03-29 08:44:35 +0000 Error: VerboseError: point is not within the bounds of the screen

please notice these commands were not swipe UP, but DOWN. and for the y:737 part, the screen size was only (414,736)

Code To Reproduce Issue [ Good To Have ]

no need

Ecxeption stacktraces

Please create a gist with pasted stacktrace of exception thrown by java.

Link to Appium logs

Needs investigation bug iOS refactor

Most helpful comment

@BrantK @truebit @nuggit32
Here is the snapshot. Just unzip it and put it to your maven repository
And don't forget change the version at your pom's to 4.0.0-SNAPSHOT.
4.0.0-SNAPSHOT.zip

All 20 comments

@truebit
Hi.
It is the server side bug which has been reported already.
https://github.com/appium/appium/issues/6292
https://github.com/appium/appium/issues/6299

After going through all these bug descriptions and related java-client source code. I think it's not server side bug.
It's the bug from java-client which does not adapt the new swipe logic in appium 1.5.
How to fix: rewrite the methods getEndX and getEndY in io.appium.java_client.SwipeElementDirection class to return relative coordinates of end x and end y

Ok. Now I've got it. I think that some refactoring is needed because the same method is used by Android and iOS now. Android still uses absolute coordinates. It seems that the swiping should be implemented differently.

@TikhomirovSergey is there a workaround for swipe until 4.0.0 is released?

@nuggit32 You can override swipe(int startx, int starty, int endx, int endy, int duration) to something like:

new TouchAction(getDriver()).press(startx, starty).waitAction(duration).moveTo(endx - startx, endy - starty).release().perform();

@truebit
I did this but got the same results as the swipe. The problem appears the X press is causing an IOS bar to pop with (Menu, views, select, move, close) options.

    Dimension dimensions = driver.manage().window().getSize();
    Double screenHeightStart = dimensions.getHeight() * 0.5;
    int scrollStart = screenHeightStart.intValue();
    Double screenHeightEnd = dimensions.getHeight() * 0.2;
    int scrollEnd = screenHeightEnd.intValue();
        new TouchAction((IOSDriver<IOSElement>) driver).press(0, scrollStart).waitAction(2000)
            .moveTo(0 - 0, scrollEnd - scrollStart).release().perform();

@truebit
Thanks for your help...The menu bar is related to debuggable app developer options. I lowed the waitAction on the press to 100 and it works. Thanks.

new TouchAction((IOSDriver) driver).press(0, scrollStart).waitAction(100)
.moveTo(0 - 0, scrollEnd - scrollStart).release().perform();

@truebit @nuggit32
The build 4.0.0 is coming soon.
Untill it is not released you can clone master and build snapshot locally and use it for your purposes.
I will keep this issue opened till 4.0.0 is published

@TikhomirovSergey Hello, thanks for all your work on Appium. I need to get around the swipe bug somehow so I cloned master and built a jar, but whenever I try to import I get the error:

"Type parameter 'org.openga.selenium.WebElement' is not within its bound: should extend 'WebElement'."

I compiled in Eclipse. Do you know what I'm doing wrong?

@BrantK
Hi.
It is much better to use IntellijIDEA instead
https://github.com/appium/java-client/blob/master/docs/Note-for-developers.md

Also I can build the SNAPSHOT and attach it to this ticket.

That'd be awesome if you could attach a snapshot! I tried to build with IntelliJ and I'm getting a bunch of these errors.

Error:(224, 12) java: The return type is incompatible with org.openqa.selenium.internal.FindsByLinkText.findElementsByPartialLinkText(String)

@BrantK @truebit @nuggit32
Here is the snapshot. Just unzip it and put it to your maven repository
And don't forget change the version at your pom's to 4.0.0-SNAPSHOT.
4.0.0-SNAPSHOT.zip

Works perfect! Thank you so much, I really appreciate it! Keep up all the good work 馃憤馃槃

The fix is published now

@TikhomirovSergey this still doesnt work for me on android.
If I try to swipe a drawer menu with
menu.swipe(SwipeElementDirection.DOWN,2000)
I get:

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1080,1776]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":13,"value":"Coordinate [x=390.0, y=1893.0] is outside of element rect: [0,0][1080,1776]"}

@rompic Can you please log this separately along with logs inform of gist

Swipe up is not working

@SrinivasanTarget
In Android We can only swipe down the list but if we want to swipe up it didn't work, using driver.swipe()

@dinkar19121991 Log a new issue with all logs needed.

Was this page helpful?
0 / 5 - 0 ratings