Need help to develop new keyword Swipe Path

I have created a new keyword, Swipe Path, to solve a problem requested by a friend. He needed to unlock an app with drawing a linear pattern (not the Android unlock, but his app under test). I was happy to create this, my first, keyword in AppiumLibrary. Now I tried to update to Appium 2, but I don’t find a way to have a positive result (or my test is bad).

Here is the source code (working fine in Appium 1) to replace AppiumLibrary at keywords :

# file: keywords/_touch.py
from appium.webdriver.common.touch_action import TouchAction

(...)

def swipe_path(self, duration=100, path=[]):
    """
    Presses down at start of `path` and releases at end of `path` with delay `duration`.
    """
    # Validate path size
    psz = len(path)
    if psz > 1 and psz % 2 == 0:
        driver = self._current_application()
        action = TouchAction(driver)
        action.press(None, path[0], path[1])
        for i in range(2, psz, 2):
            #print(f"DEBUG: x,y = {path[i]},{path[i + 1]}")
             action.wait(duration)
             action.move_to(None, path[i], path[i + 1])
        action.release().perform()

This is my test suite:

 *** Settings ***
 Documentation     demo for appium library
 Force Tags        demo
 Library           AppiumLibrary

 *** Test Cases ***
 test_demo
     [Tags]    swipe
     Open Application    http://localhost:4723/wd/hub    platformName=Android    platformVersion=11    deviceName=emulator-5554    browserName=Chrome    automationName=UIAutomator2    chromedriverExecutable=/home/helio2/chromedriver
     Go To Url    https://drawisland.com/
     # Start Screen Recording
     Sleep    5s
     Wait Until Page Contains Element    xpath=/html/body/div[6]/div[2]/div[2]/div[2]/div[2]/button[1]/p    timeout=20    # //android.widget.Button[@text="Consent"]    timeout=20
     Click Element    xpath=/html/body/div[6]/div[2]/div[2]/div[2]/div[2]/button[1]/p
     Sleep    30s
     Tap    xpath=/html/body
     @{path}=    Create List    100    100    300    100    150    300    100    100
     Swipe Path    200    ${path}
     Sleep    10s
     # Stop Screen Recording  

The new code is in my fork at branch `swipe_path` the file _touch.py .
Essentially copied from GitHub - appium/python-client: Python language bindings for Appium

There is no visible changes in the test page.

Hello!

I also have this same question and I cannot find any proper answer on the internet.

Hello! For the appium 2 TouchActions are deprecated and there are some protocol changes (Migrating from Appium 1.x to Appium 2.x - Appium Documentation) - I think it has something to do with that. For the AppiumLibrary 3.0 we stopped using TouchAction and replaced it with action_helpers.py instead ( python-client/appium/webdriver/extensions/action_helpers.py at master · appium/python-client · GitHub )

1 Like

I have also tried to make an App to test in native mode. I have used Kivy, but did not manage to build for Android. Anyway, I have the code here.
Here is a screen capture, on Windows:

1 Like

I have created the Pull Request, even if I did not get it to work: Swipe path by HelioGuilherme66 · Pull Request #453 · serhatbolsu/robotframework-appiumlibrary · GitHub

I have a project with an app and tests here

For gestures and paths, in particular, I have been thinking about how different applications, specifications, languages describe paths. For example in svg there are paths. How do they describe them.

And in addition to markers along path what else do we need to describe movement. Timing is one. How quickly do we move along a path. There might be other attributes we need to attach to a path (randomness, curves like Bézier). And what is one wants to describe not the time it takes to cover a path but what is they want a “resolution”. Then there is what if we want a path that is made up of other paths. How is this described.

Some paths are closed in that they go back to the starting point. Talking about points we have discussed different coordinate systems or words/syntax for describe a “point“ on the screen. For example go to this point, direction and distance, location of this element (it’s center, a corner of it - thinking of a closure point.

Then the higher level of gesturers. How do you create a two or three finger path. Given all these how you you easir write, create, debug these in the natural language of Robot Framework ..

As you can see the complexity of this I would like to get to a unified and complete language of gestures and paths that tie neatly together.

I have actually found a function in Beeware.org / Toga framework that has that concept, the ClosedPath. If you want, use my example project as a starting point to draw paths.

But my current struggle is just wanting to get the press-down, move, release and get the segment drawn, and I don’t find a way to get it working.

I added a comment in GitHub with a (hopefully) working solution.