一.配置连接
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.1'
desired_caps['deviceName'] = 'emulator-5554'
desired_caps['appPackage'] = 'com.liulianp.android'
desired_caps['appActivity'] = 'com.liulianp.android.module.welcome.SplashActivity'
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
ip = 'appnium的IP'
prot = 'appnium的prot'
driver = webdriver.Remote(f'http://{id}:{prot}/wd/hub', desired_caps)
二.向各个方向滑动
start_x:起始横坐标
start_y:起始纵坐标
end_x:结束横坐标
end_y:结束纵坐标
duration:起始位置到结束位置用时间单位ms
复制def get_size(driver):
'''获取长宽'''
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
return x,y
def swipeUp(driver, t=500, n=1):
'''向上滑动屏幕'''
x,y=get_size(driver)
x1 = x * 0.5
y1 = y * 0.2
y2 = y * 0.8
for i in range(n):
driver.swipe(x1, y1, x1, y2, t)
def swipeDown(driver, t=500, n=1):
'''向下滑动屏幕'''
x,y=get_size(driver)
x1 = x * 0.5
y1 = y * 0.2
y2 = y * 0.8
for i in range(n):
driver.swipe(x1, y1, x1, y2,t)
def swipLeft(driver, t=500, n=1):
'''向左滑动屏幕'''
x,y=get_size(driver)
x1 = x * 0.8
y1 = y * 0.5
x2 = x * 0.2
for i in range(n):
driver.swipe(x1, y1, x2, y1, t)
def swipRight(driver, t=500, n=1):
'''向右滑动屏幕'''
x,y=get_size(driver)
x1 = x * 0.2
y1 = y * 0.5
x2 = x * 0.8
for i in range(n):
driver.swipe(x1, y1, x2, y1, t)