appnium——app移动端的简单操作(了解)(4-1)
一. 安装/卸载/关闭/启动
1 、启动Activity:
driver.start_activity()
在当前app打开一个activity,或者新打开一个应用并启动一个activity,仅支持Android
2、安装应用:
driver.install_app('path/to/my.apk')
3、卸载应用:
driver.remove_app('com.example.android.apis')
4、关闭应用:
driver.close_app()
5、应用是否已安装:检测应用是否已被安装
driver.is_app_installed('com.example.android.apis')
二、拉取、推送文件
1、 拉取(pull)文件,从设备上拉取文件
driver.pull_file('Library/AddressBook/AddressBook.sqlitedb')
2、推送(push)文件。推送文件到设备
data = "some data for the file"
path = "/data/local/tmp/file.txt"
driver.push_file(path, data.encode('base64'))
三、锁定,将应用切换到后台
1、锁定屏幕(IOS):
driver.lock(秒)
background_app({"timeout": secs})
2、 将当前的应用切换到后台,然后可以让其在指定时间内回到前台,或者让它一直留在后台
传递给这个方法的参数有两种类型:
一个看起来像("timeout": secs)的对象。里面的secs是含义和第一个类型一样的整型数字(即表示置于后台多少秒),或者为null(表示持续置于后台)
1)持续置于后台
driver.background_app({"timeout": None})
2)置于后台5s,5s后自动回到前台
driver.background_app({"timeout": 5})
3)driver.background_app(5) #置于后台,持续5s
四、打开通知栏、摇一摇
1、打开通知栏:仅支持Android
driver.open_notifications()
2、摇一摇:模拟摇晃设备的操作
driver.shake()
3、 swipe方法上滑回去通知栏
五、手势
1、捏(Pinch)手势:缩小(默认缩小一倍),在屏幕上使用捏(Pinch)手势
driver.pinch(element=el)
2、放大屏幕(Zoom)(默认放大一倍),在屏幕上使用放大手势
driver.zoom(element=el)
3、scroll:滚动
六、按键操作keycode
1、app移动端按键地址:http://blog.csdn.net/crisschan/article/details/50419963#
2、按键发送(Android):
driver.press_keycode(键的keycode)
七、appium框架的命令
用的时候直接driver.功能
class MobileCommand(object):
CONTEXTS = 'getContexts',
GET_CURRENT_CONTEXT = 'getCurrentContext',
SWITCH_TO_CONTEXT = 'switchToContext'
TOUCH_ACTION = 'touchAction' #触屏操作
MULTI_ACTION = 'multiAction'
OPEN_NOTIFICATIONS = 'openNotifications'
GET_NETWORK_CONNECTION = 'getNetworkConnection'
SET_NETWORK_CONNECTION = 'setNetworkConnection'
GET_AVAILABLE_IME_ENGINES = 'getAvailableIMEEngines'
IS_IME_ACTIVE = 'isIMEActive'
ACTIVATE_IME_ENGINE = 'activateIMEEngine'
DEACTIVATE_IME_ENGINE = 'deactivateIMEEngine'
GET_ACTIVE_IME_ENGINE = 'getActiveEngine'
TOGGLE_LOCATION_SERVICES = 'toggleLocationServices'
LOCATION_IN_VIEW = 'locationInView'
# Appium Commands
GET_APP_STRINGS = 'getAppStrings'
PRESS_KEYCODE = 'pressKeyCode'
KEY_EVENT = 'keyEvent' # Needed for Selendroid
LONG_PRESS_KEYCODE = 'longPressKeyCode'
GET_CURRENT_ACTIVITY = 'getCurrentActivity'
GET_CURRENT_PACKAGE = 'getCurrentPackage'
SET_IMMEDIATE_VALUE = 'setImmediateValue'
PULL_FILE = 'pullFile' #上传文件,拉去文件
PULL_FOLDER = 'pullFolder'
PUSH_FILE = 'pushFile'
BACKGROUND = 'background'
IS_APP_INSTALLED = 'isAppInstalled'
INSTALL_APP = 'installApp' #安装app
REMOVE_APP = 'removeApp' #移动app
LAUNCH_APP = 'launchApp'
CLOSE_APP = 'closeApp' #关闭app
END_TEST_COVERAGE = 'endTestCoverage'
LOCK = 'lock' #锁屏
SHAKE = 'shake' #手机摇一摇
TOUCH_ID = 'touchId'
TOGGLE_TOUCH_ID_ENROLLMENT = 'toggleTouchIdEnrollment'
RESET = 'reset'
HIDE_KEYBOARD = 'hideKeyboard'
REPLACE_KEYS = 'replaceKeys'
START_ACTIVITY = 'startActivity'
GET_SETTINGS = 'getSettings'
UPDATE_SETTINGS = 'updateSettings'
SET_LOCATION = 'setLocation'
GET_DEVICE_TIME = 'getDeviceTime'
CLEAR = 'clear' #清理操作
、