学习笔记2:appium 滑动方法封装

# coding:utf-8
from appium import webdriver

desired_caps = {
"platformName": "Android",
"deviceName": "2392d777", # 通过adb devices命令获取
"platformVersion": "7.1.2",
"appPackage": "包名", # 根据所测试app的值填写
"appActivity": "appActivity", # 根据所测试app的值填写
"noReset": False,
"unicodeKeyboard": True,
"resetKeyboard": True,
}

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

def swipeUp(driver, duration=500, t=1):
# 向上滑动屏幕
a = driver.get_window_size()
start_x = a['width']/2
start_y = a['height']/5*4
end_x = a['width']/2
end_y = a['height']/5*1
for i in range(t):
driver.swipe(start_x, start_y, end_x, end_y, duration)

def swipeDown(driver, dutation=500, t=1):
# 向下滑动屏幕
a = driver.get_window_size()
start_x = a['width']/2
start_y = a['height']/5*1
end_x = a['width']/2
end_y = a['height']/5*4
for i in range(t):
driver.swipe(start_x, start_y, end_x, end_y, dutation)

def swipeRight(driver, dutation=500, t=1):
# 向左滑动屏幕
a = driver.get_window_size()
start_x = a['width']/5*4
start_y = a['height']/2
end_x = a['width']/5*1
end_y = a['height']/2
for i in range(t):
driver.swipe(start_x, start_y, end_x, end_y, dutation)

def swipeLeft(driver, dutation=500, t=1):
# 向右滑动屏幕
a = driver.get_window_size()
start_x = a['width']/5*1
start_y = a['height']/2
end_x = a['width']/5*4
end_y = a['height']/2
for i in range(t):
driver.swipe(start_x, start_y, end_x, end_y
, dutation)
if __name__ == '__main__':
swipeUp(driver, t=3)
原文地址:https://www.cnblogs.com/xiaoxin-test/p/10361800.html