Appium模擬器新app安裝後首次進入的滑動操作
阿新 • • 發佈:2021-01-03
appium獲取當前手機顯示的寬和高
driver.get_window_size()['width']
driver.get_window_size()['height']
# coding=utf-8 # 模擬移動端首次安裝手指滑動操作 from appium import webdriver def get_driver(): capabilities = {"platformName": "Android", "platformVersion": "6.0.1", # "deviceName": "bd619e047cf3", "deviceName": "127.0.0.1:7555", "app": "D:\\Android\\open_mooc_701_.apk", # "appPackage":新版Appium1.19.1無需手動配置 # "appActivity":新版Appium1.19.1無需手動配置 "appPackage":"cn.com.open.mooc", "appWaitActivity": "com.imooc.component.imoocmain.splash.GuideActivity" } driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", capabilities) return driver # driver.swipe(x,y,x1,y1) # driver.swipe(500,400,50,400) #水平從右向左滑動 # 獲取螢幕畫素的寬和高 # size = driver.get_window_size() # width = size['width']# height = size['height'] # 獲取螢幕畫素寬和高,方法封裝 def get_size(): # driver = get_driver() size = driver.get_window_size() width = size['width'] height = size['height'] return width, height # 手指向左滑動,方法封裝 def swipe_left(): x = get_size()[0] / 10 * 9 y1 = get_size()[1] / 2 x1 = get_size()[0] / 10 # driver = get_driver() driver.swipe(x, y1, x1, y1) # 手指向右滑動,方法封裝 def swipe_right(): x = get_size()[0] / 10 y1 = get_size()[1] / 2 x1 = get_size()[0] / 10 * 9 # driver = get_driver() driver.swipe(x, y1, x1, y1) # 手指向上滑動,方法封裝 def swipe_up(): x = get_size()[0] / 2 y = get_size()[1] / 10 * 9 y1 = get_size()[1] / 10 x1 = get_size()[0] / 2 # driver = get_driver() driver.swipe(x, y, x1, y1) # 手指向下滑動,方法封裝 def swipe_down(): x = get_size()[0] / 2 y = get_size()[1] / 10 y1 = get_size()[1] / 10 * 9 x1 = get_size()[0] / 2 # driver = get_driver() driver.swipe(x, y, x1, y1) # 進一步封裝,滑動的方法 def swipe_on(direction): if direction == 'up': swipe_up() elif direction == 'down': swipe_down() elif direction == 'left': swipe_left() else: swipe_right() if __name__ == '__main__': driver = get_driver() #獲取一個全域性變數 swipe_on('left') swipe_on('left')
獲取當前開啟著的appActivity
adb shell dumpsys window|findstr mCurrentFocus
連線mumu模擬器
adb connect 127.0.0.1:7555