openatx / facebook-wda

Facebook WebDriverAgent Python Client Library (not official)
MIT License
1.72k stars 266 forks source link

Swipe Method [/wda/dragfromtoforduration] Exhibiting Unexpected Inertia on iOS 17.5.1 #157

Open exculibar opened 1 month ago

exculibar commented 1 month ago

Description: I have encountered an issue with the swipe method, specifically /wda/dragfromtoforduration, on iOS 17.5.1. The method is not performing as expected, as it introduces unintended inertia during the swipe action. This behavior deviates from the anticipated results and affects the overall reliability of the swipe functionality.

Steps to Reproduce:

Execute the swipe action using the /wda/dragfromtoforduration method on an iOS 17.5.1 device.
Observe that the swipe introduces unintended inertia, contrary to expected behavior.

Expected Behavior: The swipe action should be executed without any additional inertia, providing a consistent and controlled swipe experience.

Actual Behavior: The swipe action includes unintended inertia, which affects the swipe's accuracy and responsiveness.

Environment:

iOS Version: 17.5.1
Method: /wda/dragfromtoforduration

My temporary solution:

import types
import wda

class MyAppiumClient(wda.Client):

    def session(self) -> "MyAppiumClient":
        client = super().session()
        instance = self
        client.swipe_ios = types.MethodType(
            lambda self, x1, y1, x2, y2, duration=0: instance.swipe_ios(
                x1, y1, x2, y2, duration
            ),
            client,
        )
        return client

    def swipe_ios(self, x1, y1, x2, y2, duration=0):
        """
        Args:
            x1, y1, x2, y2 (int, float): float(percent), int(coordicate)
            duration (float): start coordinate press duration (seconds)

        """
        data = {
            "actions": [
                {
                    "type": "pointer",
                    "parameters": {"pointerType": "touch"},
                    "id": "touch",
                    "actions": [
                        {
                            "type": "pointerMove",
                            "duration": 250,
                            "x": x1,
                            "y": y1,
                            "origin": "viewport",
                        },
                        {"type": "pointerDown", "duration": 0, "button": 0},
                        {
                            "type": "pointerMove",
                            "duration": duration * 1000,
                            "x": x2,
                            "y": y2,
                            "origin": "viewport",
                        },
                        {"type": "pointerUp", "duration": 0, "button": 0},
                    ],
                }
            ]
        }
        return self._session_http.post("/actions", data=data)

then

c = MyAppiumClient("http://192.168.2.131:8100")
c.wait_ready()

print(c.app_current())

s = c.session()

s.swipe_ios(150, 350, 150, 200, 3)