Appium + python - swipe滑屏操作实例

方法一:

from appium import webdriver
from time import sleep

descred_caps = {
"platformName":"Android",
"platformVersion":"5.1.1",
"deviceName":"127.0.0.1:62001",
"appPackage":"com.baidu.yuedu",
"appActivity":"com.baidu.yuedu.splash.SplashActivity",
"noRset":"true",
"unicodeKeyboard":"true",
"resetKeyboard":"true"
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",descred_caps)

#获取屏幕size
size = driver.get_window_size()
print(size)

#屏幕的宽度 width
print(size["width"])

#屏幕的高度 height
print(size["height"])

def swipeUp(driver,t=500,n=1):
"""向上屏幕滑动"""
x1 = size["width"] * 0.5 # x坐标
y1 = size["height"] * 0.75 # 起点 y坐标
y2 = size["height"] * 0.25 # 终点 y 坐标
for i in range(n):
driver.swipe(x1,y1,x1,y2,t)

def swipeDown(driver,t=500,n=1):
"""向下屏幕滑动"""
x1 = size["width"] * 0.5 # x1 坐标
y1 = size["height"] * 0.25 # 起点y1坐标
y2 = size["height"] * 0.75 # 终点y2坐标
for i in range(n):
driver.swipe(x1,y1,x1,y2,t)

def swipeLeft(driver,t=500,n=1):
"""向左屏幕滑动"""
x1 = size["width"] * 0.75 # 起点x1坐标
y1 = size["height"] * 0.5 # y1 坐标
x2 = size["width"] * 0.25 # 终点x2坐标
for i in range(n):
driver.swipe(x1,y1,x2,y1,t)

def swipeRight(driver,t=500,n=1):
"""向右屏幕滑动"""
x1 = size["width"] * 0.25 #起点x1坐标
y1 = size["height"] * 0.5 # y1坐标
x2 = size["width"] * 0.75 #终点x2坐标
for i in range(n):
driver.swipe(x1,y1,x2,y1,t)

if __name__ == "__main__":
print(driver.get_window_size())
sleep(5)
swipeLeft(driver, n=2)
sleep(2)
swipeRight(driver, n=2)
driver.quit()

方法二:
#!usr/bin/env python
#!coding:utf-8

from appium import webdriver
import time as t


class Swipe(object):
def __init__(self,driver):
self.driver=driver

@property
def width(self):
return self.driver.get_window_size()['width']

@property
def height(self):
return self.driver.get_window_size()['height']

@property
def getResolution(self):
return str(self.width)+"*"+str(self.height)

@property
def set_Left_Right(self):
'''
:return: 实现从左到右滑动,滑动时X轴起点大于终点
'''
t.sleep(2)
self.driver.swipe(self.width*9/10,self.height/2,self.width/20,self.height/2,0)

@property
def set_Right_Left(self):
'''
:return:实现从右到左滑动,滑动时X轴起点小于终点
'''
t.sleep(2)
self.driver.swipe(self.width/10,self.height/2,self.width*9/10,self.height/2,0)

@property
def set_Up_Down(self):
'''
:return: 实现从上往下滑动,滑动时Y轴起点起点大于终点
'''
t.sleep(2)
self.driver.swipe(self.width/2,self.height*9/10,self.width/2,self.height/20,0)

@property
def set_Down_Up(self):
'''
:return: 实现从下往上滑动,滑动时Y轴起点小于终点
'''
t.sleep(2)
self.driver.swipe(self.width/2,self.height/20,self.width/2,self.height*9/10,0)


转载于:https://www.cnblogs.com/Teachertao/p/10990958.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值