APPium+python_滑屏封装方法

#!/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)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值