#coding=utf-8
from appium import webdriver
def get_driver():
desc={
"platformName":"Android",
"platformVersion":"5.1.1",
"deviceName":"emulator-5554",
"appPackage":"cn.com.open.mooc",
"appActivity":".index.splash.GuideActivity"
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desc)
return driver
# desc['platformName']='Android'
# 手机版本
# desc['platformVersion']='5.1.1'
# 手机唯一标识
# desc['deviceName'] = 'emulator-5554'
# 包名
# desc['appPackage'] = 'cn.com.open.mooc'
# 入口
# desc['appActivity'] = '.index.splash.GuideActivity'
#True 重置
# desc['noReset']=True
#重置输入法
# desc['unicodeKeyboard']=True
#appium的输入法
# desc['resetKeyboard']=True
# driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desc)
#获取屏幕的宽高
def get_size():
size=driver.get_window_size()
width=size['width']
height=size['height']
return width,height
#向左滑动
def swipe_left():
x1=get_size()[0]/10*9
y1=get_size()[1]/2
x2=get_size()[0]/10
driver.swipe(x1,y1,x2,y1)
#向右滑动
def swipe_right():
x1=get_size()[0]/10
y1=get_size()[1]/2
x2=get_size()[0]/10*9
driver.swipe(x1,y1,x2,y1)
#向上滑动
def swipe_up():
x1=get_size()[0]/2
y=get_size()[1]/10*9
y1=get_size()[0]/10
driver.swipe(x1,y,x1,y1)
#向下滑动
def swipe_down():
x1=get_size()[0]/2
y=get_size()[1]/10
y1=get_size()[1]/10*9
driver.swipe(x1,y,x1,y1)
def swipe_on(direction):
if direction=='up':
swipe_up()
elif direction=='down':
swipe_down()
elif direction=='left':
swipe_left()
else:
swipe_right()
# get_size()
# swipe_left()
driver=get_driver()
swipe_on('left')