码迷,mamicode.com
首页 > 移动开发 > 详细

appium-封装屏幕滑动方法

时间:2019-08-13 13:19:55      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:width   exception   获取   exce   size   col   div   nbsp   self   

from common.logger import Logger
logger=Logger().get_logger()
class BasePage:
    def __init__(self,driver):
        self.driver=driver
    def get_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.5
            y=size[1]*0.2
            x1=size[0]*0.5
            y1=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.5
            y=size[1]*0.8
            x1=size[0]*0.5
            y1=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.2
            y = size[1] * 0.5
            x1 = size[0] * 0.8
            y1 = 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.8
            y = size[1] * 0.5
            x1 = size[0] * 0.2
            y1 = 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-封装屏幕滑动方法

标签:width   exception   获取   exce   size   col   div   nbsp   self   

原文地址:https://www.cnblogs.com/Be-your-own-hero/p/11345279.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!