Appium+Python Flick longpress press区别(Android)

在使用Appium的Python client端的写Android脚本时,发现使用flick方法输出滑动不好控制,明明是偏移量100px但是有时候滑动很快直接到底部,有时又是100px的距离。所以这样导致我们在写滑动时候很难控制滑动精确位置。经测试发现是Appium Python client端一个Bug导致。 我们通过将flick方法中press修改为longpress解决这个问题

Appium Python client API

def flick(self, start_x, start_y, end_x, end_y):
"""
  Flick from one point to another point.

:Args:
- start_x - x-coordinate at which to start
- start_y - y-coordinate at which to start
- end_x - x-coordinate at which to stop
- end_y - y-coordinate at which to stop

:Usage:
driver.flick(100, 100, 100, 400)
"""
action = TouchAction(self)
    action \
        .press(x=start_x, y=start_y) \
        .move_to(x=end_x, y=end_y) \
        .release()
    action.perform()
    return self

上文中使用的press
moveto 中 endx,endy 是相对startx,start_y的偏移量 并存在随机滑动加速度或缓冲滑动
TouchAction(driver) .press({x: 532, y: 1278}) .moveTo({x: 12: y: -371}) .release()

修改后 Appium Python client API

def flick(self, start_x, start_y, end_x, end_y):
  """
    Flick from one point to another point.

    :Args:
    - start_x - x-coordinate at which to start
    - start_y - y-coordinate at which to start
    - end_x - x-coordinate at which to stop
    - end_y - y-coordinate at which to stop

    :Usage:
    driver.flick(100, 100, 100, 400)
  """
    action = TouchAction(self)
        action \
            .long_press(x=start_x, y=start_y) \
            .move_to(x=end_x, y=end_y) \
            .release()
        action.perform()
        return self

上文使用longpress moveto 中 endx,endy 是绝对值 (startx,endx) TouchAction(driver) .press({x: 532, y: 1278}) .moveTo({x: 532: y: 1000}) .release()
其中如有错误,欢迎指正 讨论QQ群:658703911

你可能感兴趣的:(Appium+Python Flick longpress press区别(Android))