码迷,mamicode.com
首页 > 移动开发 > 详细

Appium + python - swipe滑屏操作实例

时间:2019-06-08 16:22:59      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:屏幕   pytho   idt   env   sha   swiper   com   splash   code   

方法一:

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)


Appium + python - swipe滑屏操作实例

标签:屏幕   pytho   idt   env   sha   swiper   com   splash   code   

原文地址:https://www.cnblogs.com/Teachertao/p/10990958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!