openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.57k stars 1.4k forks source link

device.swipe 行为与文档不一致 #842

Closed i1123581321 closed 5 months ago

i1123581321 commented 1 year ago

device.swipe 行为与文档不一致

环境

系统:Windows 11 22H2 Python:Python 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 uiautomator2:2.16.19 手机型号:Android studio avd Pixel 2 Android 11.0 Google apis x86_64

期望行为

按照 swipe 的 docstring,在提供了 steps 参数后,将按照参数进行 swipe,同时提供的 duration 会被忽略。期望在只提供 steps 参数时,能按照参数的数值进行滑动操作

>>> help(d.swipe)
Help on method swipe in module uiautomator2:

swipe(fx, fy, tx, ty, duration: Optional[float] = None, steps: Optional[int] = None) method of uiautomator2.Device instance
    Args:
        fx, fy: from position
        tx, ty: to position
        duration (float): duration
        steps: 1 steps is about 5ms, if set, duration will be ignore

    Documents:
        uiautomator use steps instead of duration
        As the document say: Each step execution is throttled to 5ms per step.

    Links:
        https://developer.android.com/reference/android/support/test/uiautomator/UiDevice.html#swipe%28int,%20int,%20int,%20int,%20int%29

打开 debug 模式后进行调用

>>> d.swipe(500, 50, 500, 450, steps=10)

期望得到 steps=10,即滑动时间约 50ms 的效果

实际行为

如下图

image

实际上 jsonrpc 进行调用时的 steps 为 55 而非 10,在模拟器上观察到的滑动时间也不是 50 ms

而当同时提供了 duration 参数时,不论该参数为何值,都会按照提供的 steps 参数进行调用

image