#!/usr/bin/env python
# coding:utf-8
from appium import webdriver
from time import sleep
#设置路径信息
PATH=lambda p:os.path.abspath(
os.path.join(os.path.dirname(__file__),p)
)
global driver
desired_caps ={
'platformName':'Android',
'platformVersion':'7.1.1',
'deviceName':'d03a8ee',
'appPackage':'com.lcworld.oasismedical',
'appActivity': '.splash.SplashActivity'
}
driver = webdriver.Remote('http://127.0.0.1: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)
# upper
def swipeUp(driver, t=500, n=1):
'''向上滑动屏幕'''
upper= driver.get_window_size()
x1 = upper['width'] * 0.5 # x坐标
y1 = upper['height'] * 0.75 # 起始y坐标
y2 = upper['height'] * 0.25 # 终点y坐标
for i in range(n):
driver.swipe(x1, y1, x1, y2, t)
# lower
def swipeDown(driver, t=500, n=1):
'''向下滑动屏幕'''
lower = driver.get_window_size()
x1 = lower['width'] * 0.5 # x坐标
y1 = lower['height'] * 0.25 # 起始y坐标
y2 = lower['height'] * 0.75 # 终点y坐标
for i in range(n):
driver.swipe(x1, y1, x1, y2,t)
# Left
def swipLeft(driver, t=500, n=1):
'''向左滑动屏幕'''
Left = driver.get_window_size()
x1 = Left['width'] * 0.75
y1 = Left['height'] * 0.5
x2 = Left['width'] * 0.05
for i in range(n):
driver.swipe(x1, y1, x2, y1, t)
# right
def swipRight(driver, t=500, n=1):
'''向右滑动屏幕'''
right = driver.get_window_size()
x1 = right['width'] * 0.05
y1 = right['height'] * 0.5
x2 = right['width'] * 0.75
for i in range(n):
driver.swipe(x1, y1, x2, y1, t)
if __name__ == "__main__":
print(driver.get_window_size())
sleep(2)
swipeUp(driver, n=2)
sleep(2)
swipeDown(driver, n=2)
sleep(5)
swipLeft(driver, n=2)
sleep(2)
swipRight(driver, n=2)
APPium+python_滑屏封装方法
最新推荐文章于 2024-05-16 10:09:08 发布