app、appium UI自动化之触屏操作自动化

1. TouchAction的用法
参考官方文档:

TouchAction

The available events from the spec are:
  • press
  • release
  • moveTo
  • tap
  • wait
  • longPress
  • cancel
  • perform
例如:TouchAction().press(el0).moveTo(el1).release()

MultiTouch

action0 = TouchAction().tap(el)
action1 = TouchAction().tap(el)
MultiAction().add(action0).add(action1).perform()
 以雪球app为例,点击【推荐】列表实现上拉滑动
    def test_action(self):
        action = TouchAction(self.driver)
        print(self.driver.get_window_rect())
        window_rect = self.driver.get_window_rect()
        #将屏幕的宽和高获取到
        width = window_rect['width']
        heigt = window_rect['height']
        x1 = int(width / 2)
    #横坐标不变,纵坐标从屏幕的4/5滑动到屏幕的1/5位置
        y_start = int(heigt * 4 / 5)
        y_end = int(heigt * 1 / 5)
        action.press(x=x1, y=y_start).wait(200).move_to(x=x1, y=y_end).release().perform()

模拟器中的坐标定位设置在哪里呢?如下图,将指针位置开启

 如下是手势解锁的一段操作代码:

 

原则: 如果能拿到元素的时候尽量拿元素,拿不到元素的时候拿坐标点

其他用法可参考官方文档

posted @ 2020-04-20 13:16  zhaikunkun  阅读(455)  评论(0)    收藏  举报