Appium(七)Swipe、TouchAction 操作 + 九宫格实例

       在的自动化测试过程中不可能只测试一个固定的有限界面,有的时候会遇到一些比较长的页面,这个时候就会用到滑动的操作,在 appium 中模拟用户滑动的操作需要使用 Swipe 方法,Swipe 的方法是如何定义的呢:

def swipe(self, start_x, start_y, end_x, end_y, duration=None):
   /*
    Swipe from one point to another point, for an optional duration.

    :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
     - duration - (optional) time to take the swipe, in ms.

     :Usage:
          driver.swipe(100, 100, 100, 400)
    */

1、Swipe 的分类

  • 水平滑动
  • 垂直滑动
  • 任意方向滑动

滑动的轨迹图有:

2、综合案例:

  • 测试场景

  1. 启动 豌豆荚,进入到 精选 界面
  2. 水平手动向左滑动2次
  • 执行脚本

from capability import driver
import time

# 先获取屏幕的尺寸
def get_screen_size():
    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']
    # 直接返回一个元组
    return x,y

# 向左滑动
def swipe_left():
    left = get_screen_size()
    x1 = int(left[0] * 0.9)
    y1 = int(left[1] * 0.6)
    x2 = int(left[0] * 0.2)
    driver.swipe(x1, y1, x2, y1, 3000)

# 向右滑动
def swipe_right():
    right = get_screen_size()
    x1 = int(right[0] * 0.2)
    y1 = int(right[1] * 0.6)
    x2 = int(right[0] * 0.9)
    driver.swipe(x1, y1, x2, y1, 3000)

# 向上滑动
def swipe_up():
    up = get_screen_size()
    x1 = int(up[0] * 0.5)
    y1 = int(up[1] * 0.9)
    y2 = int(up[0] * 0.3)
    driver.swipe(x1, y1, x1, y2, 3000)

# 向下滑动
def swipe_down():
    down = get_screen_size()
    x1 = int(down[0] * 0.5)
    y1 = int(down[0] * 0.3)
    y2 = int(down[1] * 0.9)
    driver.swi
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值