appnium实现向上滑动,向下滑动,向左滑动,向右滑动

【appnium实现向上滑动,向下滑动,向左滑动,向右滑动】书史足自悦,安用勤与劬。这篇文章主要讲述appnium实现向上滑动,向下滑动,向左滑动,向右滑动相关的知识,希望能为你提供帮助。
一.配置连接

from appium import webdriverdesired_caps = {} desired_caps[‘platformName‘] = ‘android‘# 系统名 desired_caps[‘platformVersion‘] = ‘5.1.1‘ # adb版本 desired_caps[‘deviceName‘] = ‘emulator-5554‘ # adb的名字 cmd输入adb devices可以查到#导出模拟器中的apk,然后使用Android Kille将APK包进行反编译 desired_caps[‘appPackage‘] = ‘com.liulianp.android‘ # app的包名 desired_caps[‘appActivity‘] = ‘com.liulianp.android.module.welcome.SplashActivity‘ # app的主入口名 desired_caps[‘unicodeKeyboard‘] = True desired_caps[‘resetKeyboard‘] = True#启动appium-desktop服务器,服务器IP根据实际填写 ip = ‘appnium的IP‘ prot = ‘appnium的prot‘ driver = webdriver.Remote(f‘http://{id}:{prot}/wd/hub‘, desired_caps)

二.向各个方向滑动
#原理使用driver.swipe方法()swipe(self, start_x, start_y, end_x, end_y, duration=None) start_x:起始横坐标 start_y:起始纵坐标 end_x:结束横坐标 end_y:结束纵坐标 duration:起始位置到结束位置用时间单位ms #你可以把它想象成手指在app界面的一开始按着的位置到结束的位置

def get_size(driver): ‘‘‘获取长宽‘‘‘ x = driver.get_window_size()[‘width‘] y = driver.get_window_size()[‘height‘] return x,ydef 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)


    推荐阅读