from appium import webdriver
from time import sleep
class Move:
# 连接客户端
def __init__(self,appPackage,appActivity):
desired_caps = {}
desired_caps['platformName'] = ''
desired_caps['platformVersion'] = ''
desired_caps['deviceName'] = ''
desired_caps['appPackage'] = appPackage
desired_caps['appActivity'] = appActivity # OPPO社区'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# 获取屏幕宽和高
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)M=Move('com.oppo.community','.InitActivity')M.getSize()sleep(3)m=100while m>1: for i in range(4): M.swipeUp(100) for x in range(4): M.swipeDown(100) m-=1
Appium+python封装四个滑动屏幕的方法【转载】
最新推荐文章于 2024-04-26 01:45:18 发布