appium中的Multiaction(多点触控)的用法

# coding: utf-8

from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.multi_action import MultiAction

"""两个手指操作屏幕"""


def pinch(driver):
    """
    两个手指向内滑
    @param driver:
    @return:
    """
    action1 = TouchAction(driver)
    action2 = TouchAction(driver)
    pinch_action = MultiAction(driver)

    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']

    action1.press(x=x * 0.8, y=y * 0.5).wait(500).move_to(x=x * 0.6, y=y * 0.5).wait(500).release()
    action2.press(x=x * 0.2, y=y * 0.5).wait(500).move_to(x=x * 0.4, y=y * 0.5).wait(500).release()

    pinch_action.add(action1, action2)
    print('start pinch...')
    pinch_action.perform()


def zoom(driver):
    """
    两个手指向外滑
    @param driver:
    @return:
    """
    action1 = TouchAction(driver)
    action2 = TouchAction(driver)
    zoom_action = MultiAction(driver)

    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']

    action1.press(x=x * 0.4, y=y * 0.5).wait(500).move_to(x=x * 0.2, y=y * 0.5).wait(500).release()
    action2.press(x=x * 0.6, y=y * 0.5).wait(500).move_to(x=x * 0.8, y=y * 0.5).wait(500).release()

    zoom_action.add(action1, action2)
    print("start zoom...")
    zoom_action.perform()

 

posted on 2022-03-30 23:46  凌风子  阅读(225)  评论(0编辑  收藏  举报