Appium移動端自動化測試之滑動封裝實戰 八

2021-09-19 13:59:44 字數 3206 閱讀 5783

driver = webdriver.remote(『

#登入sleep(5)

driver.find_element_by_id(「com.shanjian.originaldesign:id/edit_tel」).clear()

driver.find_element_by_android_uiautomator(『new uiselector().text(「輸入手機號碼」)』).send_keys(「15817252876」)

driver.find_element_by_id(「com.shanjian.originaldesign:id/edit_pwd」).send_keys(「123456」)

driver.find_element_by_android_uiautomator(『new uiselector().text(「登入」)』).click()

sleep(5)

driver.find_element_by_name(「我的」).click()

sleep(5)

print(『開始向上滑動…』)

def swipeup(t=1000,n=1):

『』『封裝向上滑動方法』』』

l = driver.get_window_size()

print(l) #dict

x1 = l[『width』] * 0.5 #獲取寬度x1

y1 = l[『height』] * 0.75 #起始值y1

y2 = l[『height』] * 0.25 #結束值y2

for i in range(n):

driver.swipe(x1,y1,x1,y2,t)

swipeup(3000)

sleep(3)

print(『開始向下滑動…』)

def swipedown(t=none,n=1):

『』『向下滑動方法』』』

l = driver.get_window_size()

print(l) # dict

x1 = l[『width』] * 0.5 # 獲取寬度x1

y1 = l[『height』] * 0.25 # 起始值y1

y2 = l[『height』] * 0.75 # 結束值y2

for i in range(n):

driver.swipe(x1, y1, x1, y2,t)

swipeup(3000)

def swipeleft(t=none,n=1):

『』『向左滑動方法』』』

l = driver.get_window_size()

print(l) # dict

x1 = l[『width』] * 0.75 # 獲取寬度x1

y1 = l[『height』] * 0.5 # 起始值y1

x2 = l[『height』] * 0.25 # 結束值y2

for i in range(n):

driver.swipe(x1, y1, x2, y1,t)

def swipedown(t=none,n=1):

『』『向右滑動方法』』』

l = driver.get_window_size()

print(l) # dict

x1 = l[『width』] * 0.25 # 獲取寬度x1

y1 = l[『height』] * 0.5 # 起始值y1

x2 = l[『height』] * 0.75 # 結束值y2

for i in range(n):

driver.swipe(x1, y1, x2, y1,t)

複製**

完整原始碼:

複製**

『』』:args:

:usage:

driver.swipe(100, 100, 100, 400)

driver = webdriver.remote(『

sleep(8)

def swipeup(driver, t=500, n=1):

『』『向上滑動螢幕』』』

l = driver.get_window_size()

x1 = l[『width』] * 0.5 # x 座標

y1 = l[『height』] * 0.75 # 起始 y 座標

y2 = l[『height』] * 0.25 # 終點 y 座標

for i in range(n):

driver.swipe(x1, y1, x1, y2, t)

def swipedown(driver, t=500, n=1):

『』『向下滑動螢幕』』』

l = driver.get_window_size()

x1 = l[『width』] * 0.5 # x 座標

y1 = l[『height』] * 0.25 # 起始 y 座標

y2 = l[『height』] * 0.75 # 終點 y 座標

for i in range(n):

driver.swipe(x1, y1, x1, y2, 1)

def swipleft(driver, t=500, n=1):

『』『向左滑動螢幕』』』

l = driver.get_window_size()

x1 = l[『width』] * 0.75

y1 = l[『height』] * 0.5

x2 = l[『width』] * 0.05

for i in range(n):

driver.swipe(x1, y1, x2, y1, t)

def swipright(driver, t=500, n=1):

『』『向右滑動螢幕』』』

l = driver.get_window_size()

x1 = l[『width』] * 0.05

y1 = l[『height』] * 0.5

x2 = l[『width』] * 0.75

for i in range(n):

driver.swipe(x1, y1, x2, y1, t)

ifname== 「main」:

print(driver.get_window_size())

sleep(8)

swipeup(driver,n=1)

sleep(8)

swipedown(driver,n=1)

複製**

1 Appium移動端自動化測試 基礎預熱

近日開始了移動端自動化測試的學習之路,決定在學習的過程中進行筆記,總結學習,印象或許會深刻一些。3 真機 啟動應用 adb shell 本身就是乙個 linux 的 shell,可以呼叫 android 內建命令 adb shell adb adb install apk pm 包管理工具,安裝 解...

Appium 自動化測試之框架

判斷是否進入到完善資訊介面 try self.driver.find element self.perfectinfomation school except nosuchelementexception logger.error register fail self.getscreenshot r...

Appium移動自動化框架

3 自動測試用例執行 4 持續整合環境jenkins,定時自動構建和執行測試任務。自動化始終圍繞乙個session 會話 進行。客戶端初始化乙個session 來與服務端互動,不同的語言有不同的實現方式,但是它們最終都是傳送乙個post 請求給服務端,請求中包含乙個json 物件,其被稱作 desi...