欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

appium 滑动屏幕方法封装

程序员文章站 2022-07-12 22:12:15
...

API:

appium 滑动屏幕方法封装

  • start_x:滑动开始x轴坐标
  • start_y:滑动开始y轴坐标
  • end_x:滑动结束x轴偏移量
  • end_y:滑动结束y轴偏移量
  • duration:(可选) 执行此次滑动时间,单位毫秒

封装

参数n:滑动次数

# 向上滑动屏幕
def swipe_up(driver, t=500, n=1):
    l = driver.get_window_size()
    x1 = l['width'] * 0.5
    y1 = l['height'] * 0.75
    y2 = l['height'] * 0.25
    for i in range(n):
        driver.swipe(x1, y1, x1, y2, t)


# 向下滑动屏幕
def swipe_down(driver, t=500, n=1):
    l = driver.get_window_size()
    x1 = l['width'] * 0.5
    y1 = l['height'] * 0.25
    y2 = l['height'] * 0.75
    for i in range(n):
        driver.swipe(x1, y1, x1, y2, t)


# 向左滑动屏幕
def swipe_left(driver, t=500, n=1):
    l = driver.get_window_size()
    x1 = l['width'] * 0.75
    y1 = l['height'] * 0.5
    x2 = l['width'] * 0.25
    for i in range(n):
        driver.swipe(x1, y1, x2, y1, t)


# 向右滑动屏幕
def swipe_right(driver, t=500, n=1):
    l = driver.get_window_size()
    x1 = l['width'] * 0.25
    y1 = l['height'] * 0.5
    x2 = l['width'] * 0.75
    for i in range(n):
        driver.swipe(x1, y1, x2, y1, t)

相关标签: python 封装