flingGesture directions are the wrong way round?

Hello all,

I was working on a method to close an Android app from the app drawer. Simulating how a user would hard close an app (I found terminateApp was causing issues with the webview in the app). I have the below which does what I need (opens recent apps and swipes up…important)

            driver.executeScript("mobile: pressKey", Map.of(
                    "keycode", 187  // https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_RECENT_APPS
            ));

            int height = driver.manage().window().getSize().getHeight();
            int width  = driver.manage().window().getSize().getWidth();

            ((JavascriptExecutor) driver).executeScript("mobile: flingGesture", ImmutableMap.of(
                    "left", 0,
                    "top", height / 3,
                    "width", width,
                    "height", height / 3,
                    **"direction", "down",**
                    "speed", 7500
            ));

As you can see, it only works when I select down. Conversely, using up will provide down actions (e.g. swiping down from the notification bar). Is this intentional? It appears to alwasy have been like this, so I’m assuming I’m missing something, but to me it’s clearly reversed.

The actual fling implementation has been copied from UiAutomator framework sources: src/main/java/android/support/test/uiautomator/UiObject2.java - platform/frameworks/uiautomator - Git at Google

As you could see there the incoming direction value gets reversed:

// To fling, we swipe in the opposite direction
final Direction swipeDirection = Direction.reverse(direction);
1 Like

Ha, that’s strange that they do that :slight_smile: . But now I understand why appium does, thanks for the response.