appium / appium-flutter-driver

Appium Flutter Driver is a test automation tool for Flutter apps on multiple platforms/OSes. Appium Flutter Driver is part of the Appium mobile test automation tool maintained by community
MIT License
470 stars 183 forks source link

Long Tap Functionality with Appium Python Client Not Working as Expected ('durationMilliseconds' of 'opts' is undefined.) #750

Closed mafahn closed 3 weeks ago

mafahn commented 3 weeks ago

I'm working with the Appium Python client to test a Flutter app, and I'm looking for a way to perform a long tap. I've already found the implementation in the scroll.ts file in this project for the longTap function and built up my Python command using the execute_script function, based on the required arguments in the ts-file function definition.

long_tap_params = {
    "elementBase64": element.id,
    "opts": {
        "durationMilliseconds": 3000,
        "frequency": 60
    }
}
driver.execute_script("flutter:longTap", long_tap_params)

Additionally, I've verified that the Appium Python client creates the expected request by capturing the request with Wireshark. The following is transmitted to Appium and matches my expectations:

{
    "script": "flutter:longTap",
    "args": [
        {
            "elementBase64": "eyJmaW5kZXJUeXBlIjoiQnlUZXh0IiwidGV4dCI6IjUwOjhjOmIxOjRmOmE0OmQ4In0=",
            "opts": {
                "durationMilliseconds": 3000,
                "frequency": 60
            }
        }
    ]
}

Unfortunately, I get the response that the argument durationMilliseconds is not correct:

UnknownError: An unknown server-side error occurred while processing the command. Original error: Cannot destructure property 'durationMilliseconds' of 'opts' as it is undefined.
    at getResponseForW3CError (/usr/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/errors.js:1145:9)
    at asyncHandler (/usr/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:485:57)
    at runNextTicks (node:internal/process/task_queues:65:5)
    at processImmediate (node:internal/timers:459:9)
    at process.callbackTrampoline (node:internal/async_hooks:130:17)

Has anyone had experience performing a long tap using the Appium Python client, or can anyone help me understand what's wrong?

KazuCocoa commented 3 weeks ago

How about driver.execute_script("flutter:longTap", finder, {"durationMilliseconds": 3000, "frequency": 60})? Similar to https://github.com/appium/appium-flutter-driver/blob/main/example/python/example.py#L40

mafahn commented 3 weeks ago

Thanks, @KazuCocoa!

After revisiting the example you linked, I noticed the difference in handling the element parameter. Originally, I passed element.id in my long_tap_params, but in the example, the entire element object was used instead.

Updating my code to pass element directly instead of element.id resolved the issue, and now the durationMilliseconds parameter is correctly recognized. Thanks again for the help — much appreciated!

Here’s the working code snippet; __get_element_by_key returns a FlutterElement object:

element = self.__get_element_by_key(driver, value_key, timeout=timeout)
driver.execute_script(
    "flutter:longTap",
    element,
    {
        "durationMilliseconds": press_duration,
        "frequency": 60
    }
)