Appium行为事件处理

学向勤中得,萤窗万卷书。这篇文章主要讲述Appium行为事件处理相关的知识,希望能为你提供帮助。
1.查看源码语法,起点和终点四个坐标参数,duration是滑动屏幕持续的时间,时间越短速度越快。默认为None可不填,一般设置500-1000毫秒比较合适。
swipe(self, start_x, start_y, end_x, end_y, duration=None)
Swipe from one point to another point, for an optional duration.
从一个点滑动到另外一个点,duration是持续时间
:Args:
- start_x - 开始滑动的x坐标 -
start_y - 开始滑动的y坐标 -
end_x - 结束点x坐标 -
end_y - 结束点y坐标 -
duration - 持续时间,单位毫秒
:Usage:
driver.swipe(100, 100, 100, 400)
2.手机从左上角开始为0,横着的是x轴,竖着的是y轴
获取坐标# coding:utf-8 from appium import webdriver
des_leidian = {
"platformName": "android",
"deviceName": "CLB0219103005568",
"platformVersion": "9",
"appPackage": "com.mmc.feelsowarm",
"appActivity": "com.mmc.feelsowarm.WelcomeActivity",
"noReset": True
}
driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps)
# 获取屏幕的size
size = driver.get_window_size()
# 屏幕宽度width
print(size[‘width‘])
 
# 屏幕高度width
print(size[‘height‘])
运行结果:
{u‘width‘: 720, u‘height‘: 1280}
720
1280
 
 
封装滑动方法1.把上下左右四种常用的滑动方法封装,这样以后想滑动屏幕时候就能直接调用了
参数1:driver
【Appium行为事件处理】参数2:t是持续时间
参数3:滑动次数

Appium行为事件处理

文章图片

 
def swipe_up(self, n=1):
‘‘‘
往上滑
:param driver:
:return:None
‘‘‘
x1 = self.fenbianlv[‘width‘]/2
y1 = self.fenbianlv[‘height‘] * 3 /4
x2 = self.fenbianlv[‘width‘]/2
y2 = self.fenbianlv[‘height‘] /4
for i in range(n):
self.driver.swipe(x1, y1,x2, y2, 500)
def swipe_down(self, n=1):
‘‘‘
往下滑
:param driver:
:return: None
‘‘‘
x1 = self.fenbianlv[‘width‘]/2
y1 = self.fenbianlv[‘height‘] /4
x2 = self.fenbianlv[‘width‘]/2
y2 = self.fenbianlv[‘height‘] * 3 /4
for i in range(n):
self.driver.swipe(x1, y1,x2, y2, 500)
def swipe_left(self, n=1):
‘‘‘
往左滑
:param driver:
:return: None
‘‘‘
x1 = self.fenbianlv[‘width‘]*3/4
y1 = self.fenbianlv[‘height‘] /2
x2 = self.fenbianlv[‘width‘]/4
y2 = self.fenbianlv[‘height‘] /2
for i in range(n):
self.driver.swipe(x1, y1,x2, y2, 500)
def swipe_right(self, n=1):
‘‘‘
往右滑
:param driver:
:return: None
‘‘‘
x1 = self.fenbianlv[‘width‘]/4
y1 = self.fenbianlv[‘height‘] /2
x2 = self.fenbianlv[‘width‘]*3 /4
y2 = self.fenbianlv[‘height‘]/2
for i in range(n):
self.driver.swipe(x1, y1,x2, y2, 500)

    推荐阅读