App自動化滑動操作-swipe


App自動化滑動操作封裝:

class Base_Page:
    def __init__(self, driver):
        self.driver = driver

    def width(self):
        """
        獲取屏幕寬度
        :return:
        """
        return self.driver.get_window_size()['width']

    def height(self):
        """
        獲取屏幕高度
        :return:
        """
        return self.driver.get_window_size()['height']

    def swipe_left(self):
        """
        向左滑動
        :return:
        """
        return self.driver.swipe(self.width() * 0.9 , self.height() * 0.5, self.width() * 0.1 , self.height() * 0.5)

    def swipe_right(self):
        """
        向右滑動
        :return:
        """
        return self.driver.swipe(self.width() * 0.9, self.height() * 0.5, self.width() * 0.1, self.height() * 0.5)

    def swipe_up(self):
        """
        向上滑動
        :return:
        """
        return self.driver.swipe(self.width() * 0.5, self.height() * 0.9, self.width() * 0.5, self.height() * 0.1)

    def swipe_down(self):
        """
        向下滑動
        :return:
        """
        return self.driver.swipe(self.width() * 0.5, self.height() * 0.1, self.width() * 0.5, self.height() * 0.9)

    def swipe(self, direction):
        """

        :param direction: 操作方法
        :return:
        Usage:swipe('left')	
        """
        # 映射
        swipe_action = {
            'left': self.swipe_left,
            'right': self.swipe_right,
            'up': self.swipe_up,
            'down': self.swipe_down
        }
        # 判斷是否有條件映射
        if direction not in swipe_action:
            raise ValueError('參數不正確')
        # 調用方法返回滑動操作
        return swipe_action[direction]()
    
if __name__ == '__main__':
    print(__name__)


免責聲明!

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



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