appium-封装屏幕滑动方法
Posted be-your-own-hero
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了appium-封装屏幕滑动方法相关的知识,希望对你有一定的参考价值。
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-封装屏幕滑动方法的主要内容,如果未能解决你的问题,请参考以下文章
appium+python自动化24-滑动方法封装(swipe)转载