TouchAction 用法
- 网址:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/touch-actions.md
- TouchAction
- 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()
def test_touchaction(self):
action=TouchAction(self.driver)
# 获取当前屏幕的大小
width = self.driver.get_window_rect()['width']
height = self.driver.get_window_rect()['height']
x1 = int(width/2)
y_start = int(height * 4/5)
y_end = int(height * 1/5)
action.press(x=x1, y=y_start).wait(200).move_to(x=x1, y= y_end).release().perform()
手势操作
TouchAction(driver).press(x=244,y=374).wait(100).move_to(x=711,y=374).wait(100).move_to(x=1198,y=374).wait(100).move_to(x=1198,y=865).wait(100) .move_to(x=1198,y=1323).wait(100).release().perform()
- 例子
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
class TesetTouchAction:
def setup(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
# desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = '127.0.0.1:7555'
desired_caps['appPackage'] = 'cn.kmob.screenfingermovelock'
desired_caps['appActivity'] = 'com.samsung.ui.MainActivity'
desired_caps['noReset'] = 'true'
# desired_caps['dontStopAppOnReset'] = "true"
desired_caps['skipDeviceInitialization'] = "true"
"""当要输入中文时需要以下两个参数"""
desired_caps['unicodeKeyBoard']='true'
desired_caps['resetKeyBoard']='true'
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
# 隐式等待
self.driver.implicitly_wait(5)
def teardown(self):
self.driver.quit()
def test_touchaction_unlock(self):
action = TouchAction(self.driver)
action.press(x=244, y=374).wait(100).move_to(x=711, y=374).wait(100).move_to(x=1198, y=374).\
wait(100).move_to(x=1198, y=865).wait(100).move_to(x=1198, y=1323).wait(100).release().perform()
下一节:高级定位技巧,XPath、UIAutomator定位表达式以及滑动定位应用。