appium 封裝螢幕滑動方法

2022-09-02 01:45:08 字數 2213 閱讀 2347

from common.logger import

logger

logger=logger().get_logger()

class

basepage:

def__init__

(self,driver):

self.driver=driver

defget_window_size(self):

logger.info(

"正在準備獲取當前螢幕的大小")

try:

size=self.driver.get_window_size()

width=size["

width"]

height=size["

height"]

logger.info(

"獲取當前螢幕大小成功:寬:{} 高:{}

".format(width,height))

return

width,height

except

: logger.exception(

"獲取當前螢幕大小失敗")

def swipe_down(self,t=500,n=1):

logger.info(

"正在準備向下滑動螢幕")

try:

size=self.get_window_size()

x=size[0]*0.5y=size[1]*0.2x1=size[0]*0.5y1=size[1]*0.8

for i in

range(n):

self.driver.swipe(x,y,x1,y1,t)

logger.info(

"螢幕第{}次向下滑動成功

".format(i+1))

except

: logger.exception(

"螢幕向下滑動失敗")

def swipe_up(self,t=500,n=1):

logger.info(

"正在準備向上滑動螢幕")

try:

size=self.get_window_size()

x=size[0]*0.5y=size[1]*0.8x1=size[0]*0.5y1=size[1]*0.2

for i in

range(n):

self.driver.swipe(x,y,x1,y1,t)

logger.info(

"螢幕第{}次向上滑動成功

".format(i+1))

except

: logger.exception(

"螢幕向上滑動失敗")

def swipe_right(self,t=500,n=1):

logger.info(

"正在準備向右滑動螢幕")

try:

size =self.get_window_size()

x = size[0] * 0.2y = size[1] * 0.5x1 = size[0] * 0.8y1 = size[1] * 0.5

for i in

range(n):

self.driver.swipe(x, y, x1, y1, t)

logger.info(

"螢幕第{}次向右滑動成功

".format(i + 1))

except

: logger.exception(

"螢幕向右滑動失敗")

def swipe_left(self, t=500, n=1):

logger.info(

"正在準備向左滑動螢幕")

try:

size =self.get_window_size()

x = size[0] * 0.8y = size[1] * 0.5x1 = size[0] * 0.2y1 = size[1] * 0.5

for i in

range(n):

self.driver.swipe(x, y, x1, y1, t)

logger.info(

"螢幕第{}次向左滑動成功

".format(i + 1))

except

: logger.exception(

"螢幕向左滑動失敗

")

Appium 螢幕頁面滑動(swipe函式實現)

一 簡介 二 使用案例 在滑動之前,我們需要獲取螢幕的寬度和高度,如下 dimension dimension driver.manage window getsize int width dimension.getwidth int height dimension.getheight 滑動 如下...

Appium滑動函式 Swipe

swipe 滑動api swipe int start x,int start y,int end x,int y,duration 解釋 int start x 開始滑動的 x座標 int start y 開始滑動的 y座標 int end x 結束點 x座標 int end y 結束點 y座標 ...

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

driver webdriver.remote 登入sleep 5 driver.find element by id com.shanjian.originaldesign id edit tel clear driver.find element by android uiautomator n...