Appium 自动化测试 滑动 Swipe 详解

简介

我们在做移动端自动化测试的时候,有些按钮在当前屏幕不显示,需要滑动几次屏幕后才会出现或者有些操作需要滑动屏幕,这时候,我们需要使用代码来模拟手指的滑动,本次我们先讲解Appium 里面滑动swipe方法使用

手机上坐标说明

手机从左上角开始为0,横着的是x轴,竖着的是y轴
在这里插入图片描述

swipe介绍

说明

从一个坐标位置滑动到另一个坐标位置,只能是两个点之间的滑动。

方法详情

    def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration: int = 0) -> T:
        """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: time to take the swipe, in ms.

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

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        """
        actions = ActionChains(self)
        actions.w3c_actions = ActionBuilder(self, mouse=PointerInput(interaction.POINTER_TOUCH, "touch"))
        actions.w3c_actions.pointer_action.move_to_location(start_x, start_y)
        actions.w3c_actions.pointer_action.pointer_down()
        actions.w3c_actions.pointer_action.pause(duration / 1000)
        actions.w3c_actions.pointer_action.move_to_location(end_x, end_y)
        actions.w3c_actions.pointer_action.release()
        actions.perform()
        return self

核心参数说明:
:Args:
- start_x - 开始滑动的x坐标
- start_y - 开始滑动的y坐标
- end_x - 结束点x坐标
- end_y - 结束点y坐标
- duration - 持续时间,单位毫秒,默认为 0 ms

实战

  • 从坐标点(400, 700)滑动到坐标点(400,200),duration=0

    driver.swipe(start_x=400, start_y=700, end_x=400, end_y=200)

  • 从坐标点(400, 700)滑动到坐标点(400,200),duration=500

    driver.swipe(start_x=400, start_y=700, end_x=400, end_y=200,duration=500)

  • 从坐标点(400, 700)滑动到坐标点(400,200),duration=2000

    driver.swipe(start_x=400, start_y=700, end_x=400, end_y=200,duration=2000)

  • 从坐标点(400, 700)滑动到坐标点(400,600),duration=500

    driver.swipe(start_x=400, start_y=700, end_x=400, end_y=200,duration=500)

  • 从坐标点(400, 700)滑动到坐标点(400,400),duration=500

    driver.swipe(start_x=400, start_y=700, end_x=400, end_y=200,duration=500)

  • 从坐标点(400, 700)滑动到坐标点(400,200),duration=500

    driver.swipe(start_x=400, start_y=700, end_x=400, end_y=200,duration=500)

结论

  • 距离相同时,持续时间越长,惯性越小
  • 持续时间相同时,手指滑动的距离越大,实际滑动的距离也就越大

以上为内容纯属个人理解,如有不足,欢迎各位大神指正!

如果觉得文章不错,欢迎关注微信公众号,微信公众号定期推送相关测试技术文章
个人微信号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

测试之路king

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值