注:
所有方法在使用的时候都需要使用"device."去调用
即device.type('123')
1. void drag(tuple start, tuple end, float duration, integer steps)
拖拽
传递参数坐标时要按照坐标点来传,即数组形式(x,y),drag函数会自动解析成startx,y endx y
duration和steps可以使用默认值, duration为1.0,steps为10
e.g.
start = (300,200)
end = (60,200)
device.drag(start,end,1,10)
2. void touch(int x,int y,type);
点击
传递参数坐标/type
type(仅有三种DOWN、UP、DOWN_AND_UP)。
type可以传空,也可以传 'DOWN_AND_UP',即 type=' '或者 type= 'DOWN_AND_UP'
MonkeyRunner中自动赋值
3. void type(String message)
输入
直接传递要输入内容
4. void press(string name,string type)
按键
type即 up down down_and_up
name是android常用按键,总结如下
- Home键:KEYCOD_HOME
- Back键:KEYCODE_BACK
- send键:KEYCODE_CALL
- end键:KEYCODE_ENDCALL
- power键:KEYCODE_POWER
- camera键:KEYCODE_CAMERA
- menu键:KEYCODE_MENU
- search键:KEYCODE_SEARCH
- call键:KEYCODE_CALL
- 按下HOME键 device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP)
- 按下BACK键 device.press('KEYCODE_BACK',MonkeyDevice.DOWN_AND_UP)
- 输入回车device.press('KEYCODE_ENTER',MonkeyDevice.DOWN_AND_UP)
- 返回device.press('KEYCODE_BACK',MonkeyDevice.DOWN_AND_UP)
5. void GetProperty(string key) or getSystemProperty(String key)
得到手机的一些属性
e.g. getProperty(display:width)
getProperty('build.type')
下列key来自Android文档
6. void shell(string cmd)
执行shell命令并返回结果
e.g.:device.shell('date')
执行时可能有编码问题,具体问题具体解决吧
7. void installPackage(string path)
安装指定路径的APK文件。如果改文件已安装,则会覆盖安装
e.g.:device.installPackage('e:/c1ao.apk')
8. void removePackage(string package)
删除指定包,包含所有数据
e.g. device.removePackage('com.android.dig'),具体要卸载的apk去 shell模式下data/data去查找
9. void startActivity(component)
package = 'com.android.androidui'
activity = '.MainActivity'
component = package+'/'+activity
package和Activity可以根据SDK中build-tool下aapt命令查看
aapt dump badging E:\testapp\androidUI.apk
e.g.
device.startActivity(component)
10. void reboot(string into)
重启设备
string into,有3种重启选项——“bootloader”、“recovery”和“None”。
- ·传入“bootloader”,即传说中的Bootloader重启(类似于PC的BIOS设置,可以设置软硬件环境),设备重启后进入bootloader环境。
- ·传入“recovery”,即传说中的Recovery重启(一般刷机都是这个模式),设备重启后进入recovery环境。
- ·传入“None”,即传说中的普通重启,设备重启
11. void wake()
唤醒设备
12. void broadcastIntent(string uri, string action, string data, string mimetype, iterable categories, dictionary extras, component component, iterable flags)
参数详细说明如下。
- ·string uri,设置Intent的URI,参见Intent.setData()。
- ·string action,设置Intent的Action,参见Intent.setAction()。
- ·string data,设置Intent的Data,参见Intent.setData()。
- ·string mimetype,设置Intent的MIME type,参见Intent.setType()。
- ·iterable categories,设置Intent的Categories,参见Intent.addCategory()。
- ·dictionary extras,设置Intent的extra data,参见Intent.putExtra()。
- ·component component,设置Intent的ComponentName。
- ·iterable flags,设置Intent的flags,参见Intent.setFlags()。
13. dictionary instrument(string className, dictionary args)
对于instrument,需要传入待测Instrumentation的用例类名和包名,还需提供Instrumentation的testrunner(如android.test.InstrumentationTestRunner)。
参数详细说明如下。
- ·string className,Android组件名,包名与类名都必须完整提供。
- ·dictionary args,提供dictionary型标识(flag)及其值,若标识无值则值为空字串。