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