Appium+IOS中的滑动屏幕函数swipe

今天在写IOS UI自动化脚本,启动页有两张图需要滑动,第一反应就是想到了swipe函数。

   于是就写了下面代码:

第一段是获取屏幕尺寸,由于测试机并不固定,所以还是建议动态去获取屏幕尺寸,避免换个手机测试就要更改代码

telPa = self.driver.get_window_size()
self.width = telPa["width"]
self.height = telPa["height"]


然后就是获取坐标移动

 
x1 = int ( self .width * 3 / 4 )
y1 = int ( self .height * 1 / 2 )
x2 = int ( self .width * 1 / 4 )
self .driver.swipe(x1, y1, x2, y1 , 500 )
然后运行,我发现了什么。。。。无论是x1到x2, 还是x2移动到x1,都是从左向右。。。
点击源码,查看如下

# convenience method added to Appium (NOT Selenium 3)
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)
    """
    # `swipe` is something like press-wait-move_to-release, which the server
    # will translate into the correct action
    action = TouchAction(self)
    action \
        .press(x=start_x, y=start_y) \
        .wait(ms=duration) \
        .move_to(x=end_x, y=end_y) \
        .release()
    action.perform()
    return self

# convenience method added to Appium (NOT Selenium 3)
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

两个函数试过之后,依旧如此,心塞塞。。。

搜索中,意外发现一条消息:

在appium1.5版本以下,swipe的方法中的end_x和end_y是实际要滑动的目的地坐标

但是在1.5版本以上的,end_x和end_y是相对于前面start_x和start_y坐标的偏移量。

更改代码,

x1 = int(self.width * 3/4)
y1 = int(self.height * 1/2)
x2 =tst.changeInt(x1)
print  x1,x2
self.driver.swipe(x1, y1, x2, 0,500)


运行OK 

无fuck说


                
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值