Swipe solutions

Hello there!

As long as most of swipe documentation and forum posts are old or deprecated I want to understand current Appium swipe behavior with TouchAction.

First of all: TouchAction vs. TouchActions (Java client)

I suppose many people realizes that exists 2 similar classes. TouchAction (singular) that comes from io.appium.java_client package and TouchActions (plural) that is defined in org.openqa.selenium.interactions.touch package.

If there exists any doubt the election is obvious: you’re automating on Appium → you use io.appium.java_client classes

But watching at TouchActions operation it seems to be possible to perform mobile operations as ‘longPress’, ‘doubleTap’, … I didn’t go futher, just curious about this class.

The standard swipe action

TouchAction<?> action = new TouchAction<>(driver);
WaitOptions wait = new WaitOptions().withDuration(Duration.ofMillis(duration));
action.press(PointOption.point(startX, startY)).waitAction(wait).moveTo(PointOption.point(endX, endY)).release().perform();

This is a standard swipe action. Just press on some coordinates, waits some time, moves ‘finger’ while pressing to another coordinates and releases finger.

press vs. longPress

One of the first things I realized is that exists 2 pressing actions: press and longPress. In my experience I usually use press but sometimes I need to use longPress. Not sure why. My usually workaround is:

Use press. If it doesn’t swipe the screen then use longPress. If longPress performs a tap instead of a swipe then look for another region to swipe and repeat until it works.

I try as most as I can to use relative coordinates to the screen or element locations/sizes, but sometimes swipe is really really hard to perform.

So, what implies use press or longPress and what are the best practices?

When to wait?

Another point to understand is the wait action. As long I can understand the wait actions is for simulating the duration of a real swipe, but I think that isn’t a smooth swipe… For a smooth swipe I mean that the finger takes some time to move from the origin to the end coordinates, it doesn’t stop.
As far I can see an Appium swipe works as following: press somewhere, wait some time, then move to another coordinates and at last release finger. It isn’t smooth, just after waiting the ‘finger’ moves instantly to the end coordinates. That instant move it’s the cause (I think) that an standard Appium swipe doesn’t work in common swiping scenarios (show a lateral menu from the edge, drag a list element for showing the ‘trash’ or edit buttons, …). Sometimes I’ve that feeling about waitAction that is not useful at all in a swipe action. Really confusig.

In other examples I’ve found that the waitAction is performed after the moveTo. The times I tried I feel its the same than waiting before moveTo. This fact gives strength to my theory that Appium swipe isn’t smooth.

So… It’s possible to achieve an smooth swipe in Appium? Best practices for waiting?

I think that’s all folks.
Let’s compilate some useful workarounds about swiping and post it in tutorials/documentation section :slight_smile:

1 Like

You could also try W3C actions if you need some more precise solution

@mykola-mokhnach to the rescue!

It’s just what I’ve looking for. Bad gestures for bad people, thank you!