Swipe Question(s)

I have a question or two about Swipe:

I’ll use the following command as reference for my questions:

appiumDriver.executeScript(“experitest:client.swipe(“DOWN”, 667, 2000)”);

1: the 2000 is SWIPE time…looks like this value is some form of delay as to when the swipe actually happens, correct ? The time has nothing to do with how much is actually swiped onto/off-of the screen ?

2: the 667 offset… suppose this value is 1/2 my screen size. When I swipe, will the this simply move the next 667 worth of elements onto the UI ?? I want to make sure I can’t swipe greater than a full UI size at any single time. Ideally I’d just swipe on enough elements to fill up half the screen I just scrolled off.

Please provide more detail on the swipe mechanics.

thanks

Hi,

The Swipe time means how much time tooks the swipe action from the offset point to the border of the screen. When the swipe action reachs the border of the screen the content still moves, and here is when the speed affects how much is still moving (faster = more content)

To avoid to much ‘swipping’ you must play with speed and offset to minimize the inertial scrolling effect.

“playing with speed” leads to unpredictable results if we run the same tests on different machines. There should be a more programmatically predictable mechanism.

If you have plans to run same script in different devices you’ll always face the problem with screen resolution.

One swipe action in an Galaxy S7 with a QuadHD screen resolution it never work the same in a Huawei P8 with a screen resolution of 1024*768 you must adapt your scripts to run in both devices.

One solution is to have in your script setting what kind of device is running the script and make some actions to make a longer/shorter swipe depending of screen resolution.

I’m running same scripts in Samsung Galaxy S7, Huawei P8Lite,Motorola Z2Play… and in some scripts every device have specific action to prepare next step.

Another way is to make a lot of small swipes until you find what you’re looking for and stop ‘swipping’

1 Like

I think the better response is for Appium Studio to control the swipe, and only allow a max of the displaced offset to be moved in upon a swipe. Studio has all the knowledge necessary to provide this level of control. Automation sw should NOT need to concern itself with this detail.

Experitest, what say you ??

Hi Walter

The 667 is the offset from the swipe direction (e.g - Where should the swipe action start from)

The 2000, just like mateo said is the duration of the swipe in time, where :

  1. Shorter time means longer swipe distance (exactly like the nice video that he shared - displayed here And see it Here

  2. I do agree that this doesn’t always gets you the most accurate results

The values (time \ offset) are usually calculated as parameters from the device screen size e.g -

int offset = driver.manage().window().getSize().getHeight() / 2; // start from mid screen
int time = driver.manage().window().getSize().getHeight() * 0.3; // just an example

the other options you can play around with are

A. client - SwipeWhileNotFound
B. client - ElementListSelect (works only for instrumented apps - and on ListViews) - uses the app’s internal API, and is similar to the way that scrollIntoView works on web, though it requires instrumentation doesn’t work on all types of scroll views \ screens
C. driver - TouchAction - e.g

	TouchAction touchAction = new TouchAction(driver);
		WebElement phone = driver.findElement(in.Repo.obj("apps.Phone"));
		WebElement contact = driver.findElement(in.Repo.obj("apps.Contacts"));
		touchAction.press(phone)
		.waitAction(200)
		.moveTo(contact)
		.release()
		.perform();

Hi Tom;

Thanks for the thorough response.

It would seem that Appium Studio could provide a mode that provides a predictable “size” of swipe-able data so that swipes can be move accurate. If I swipe starting with an offset of 50% of screen, Studio should be able to fill the 50% upon swipe, in a controllable manner. This would be an extremely useful feature.

I will try the time calculation mentioned above . I assume the studio controls the “speed” of the swipe and it will NOT be different on different machines ? (high horsepower vs low horsepower). Without such control, the time calculation is almost meaningless.

I will also look at the swipeWhileNotFound…perhaps thats the best way assuming one has and element destination in mind, which is normally the case.