Appium 滑動界面swipe用法


Appium 滑動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坐標。

   duration 滑動時間(默認5毫秒);

 

代碼:

 

// 分辨率

 

int widht = driver.manage().window().getSize().width;

int height = driver.manage().window().getSize().height;

for(int i = 0; i<3; i++){

// 向左滑動!

driver.swipe(widht*6/7, height/2, widht/7, height/2, 2);

 

Python-appium手機自動測試如何實現滑動呢,在webdriver 的api中只提供了指定兩個坐標的滑動,但不同的手機分辨率不同,這樣寫出來的自動化腳本兼容性就不是那么好了。。那么怎么實現滑動呢,仔細看了下webdriber中的方法,發現有個方法get_window_size() ,這個方法可以獲得手機的寬度和高度,這樣我們就可以實現按屏幕比率滑動了。。具體方法如下:

 

#獲取屏幕寬和高

 def getSize(self):

        x=self.driver.get_window_size()['width']
        y=self.driver.get_window_size()['height']
        return(x,y)

    

#向左滑動

    def swipeLeft(self,t):
        l=self.getSize()
        x1=int(l[0]*0.75)
        y1=int(l[1]*0.5)
        x2=int(l[0]*0.25)
        self.driver.swipe(x1,y1,x2,y1,t)

        

#向右滑動

    def swipeRight(self,t):
        l=self.getSize()
        x1=int(l[0]*0.25)
        y1=int(l[1]*0.5)
        x2=int(l[0]*0.75)
        self.driver.swipe(x1,y1,x2,y1,t)

        

#向上滑動

    def swipeUp(self,t):
        l=self.getSize()
        x1=int(l[0]*0.5)
        y1=int(l[1]*0.75)
        y2=int(l[1]*0.25)

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

 

#向下滑動

    def swipeDown(self,t):
        l=self.getSize()
        x1=int(l[0]*0.5)
        y1=int(l[1]*0.25)
        y2=int(l[1]*0.75)
        self.driver.swipe(x1,y1,x1,y2,t)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM