大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
使用SDK自带的NotePad应用作为实践目标应用,目的是对MonkeyDevice拥有的成员方法做一个初步的了解。
南宁ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!以下是官方列出的方法的Overview。
Return Type | Methods | Comment |
void | broadcastIntent (string uri, string action, string data, string mimetype, iterable categories dictionary extras, component component, iterable flags) Broadcasts an Intent to this device, as if the Intent were coming from an application. | |
void | drag (tuple start, tuple end, float duration, integer steps) Simulates a drag gesture (touch, hold, and move) on this device's screen. | |
object | getProperty (string key) Given the name of a system environment variable, returns its value for this device. The available variable names are listed in the detailed description of this method. | |
object | getSystemProperty (string key) . The API equivalent of adb shell getprop use by platform developers. | |
void | installPackage (string path) Installs the Android application or test package contained in packageFile onto this device. If the application or test package is already installed, it is replaced. | Obsolete,返回值是Boolean |
dictionary | instrument (string className, dictionary args) Runs the specified component under Android instrumentation, and returns the results in a dictionary whose exact format is dictated by the component being run. The component must already be present on this device. | |
void | press (string name, dictionary type) Sends the key event specified by type to the key specified by keycode. | |
void | reboot (string into) Reboots this device into the bootloader specified by bootloadType. | |
void | removePackage (string package) Deletes the specified package from this device, including its data and cache. | Obsolete,返回值是Boolean |
object | shell (string cmd) Executes an adb shell command and returns the result, if any. | |
void | startActivity (string uri, string action, string data, string mimetype, iterable categories dictionary extras, component component, flags) Starts an Activity on this device by sending an Intent constructed from the supplied arguments. | |
MonkeyImage | takeSnapshot() Captures the entire screen buffer of this device, yielding a MonkeyImage object containing a screen capture of the current display. | |
void | touch (integer x, integer y, integer type) Sends a touch event specified by type to the screen location specified by x and y. | |
void | type (string message) Sends the characters contained in message to this device, as if they had been typed on the device's keyboard. This is equivalent to callingpress() for each keycode in message using the key event type DOWN_AND_UP. | |
void | wake () Wakes the screen of this device. |
其实官方这个表是没有及时更新的,我现在手头上用到的MonkeyRunner是当前最新的,里面就拥有好几个官网没有列出来的API,我怀疑是不是自从UIAutomator在03年出来后,google就不打算再继续维护MonkeyRunner了?如果有朋友知道事实的话,还麻烦告知。
以下是我整理出来的源码多出来的可用公共API列表
Return Type | Methods | Comment |
HierarchyViewer | getHierarchyViewer(PyObject args[], String kws[]) 获取一个HierarchyViewer对象 | 请查看《MonkenRunner通过HierarchyViewer定位控件的方法和建议》 |
PyList | getPropertyList(PyObject args[], String kws[]) | 取得所有的property属性键值 |
PyList | getViewIdList(PyObject args[], String kws[]) | Failed |
MonkeyView | getViewById(PyObject args[], String kws[]) | Failed |
MonkeyView | getViewByAccessibilityIds(PyObject args[], String kws[]) | Failed |
MonkeyView | getRootView(PyObject args[], String kws[]) | Failed |
PyList | getViewsByText(PyObject args[], String kws[]) | Failed |
但可惜的是在本人尝试以上多出来的API的时候,发现除了最上面两个可用之外,其他的都不可用并抛出错误。且网上资料少的可怜,别人碰到同样的问题也找不到解决办法。所以本人怀疑这些“隐藏”API是不是并没有完善,或者说google不准备完善,所以才没有列出到官网上面去。本人用的SDK tools和Platform tools已经是当前最新的23.0.2和20.
一个台湾网友碰到的问题描述:http://imsardine.simplbug.com/note/monkeyrunner/api/hierarchy-viewer.html
(string uri, string action,string data, string mimetype, iterable categories dictionary extras, componentcomponent, iterable flags)
本人理解的此方法的本意是想广播一个Intent给我们的AndroidDevice,目标应用接收到该Intent做相应的处理,比如打开一个Activity等。但在我的多次尝试下并没有成功!
targetDevice.broadcastIntent(action='android.intent.action.INSERT', mimetype='vnd.android.cursor.dir/contact', extras = {'name':'user1501488', 'phone':'123-15489'}
如果使用同样的参数,使用下面的startActivity是没有问题的。
targetDevice.startActivity(action='android.intent.action.INSERT', mimetype='vnd.android.cursor.dir/contact', extras = {'name':'user1501488', 'phone':'123-15489'})
google了半天网上根本找不到这个方法的使用例子,倒是stackOverFlow上有人建议用Shell来达到同样的效果。
targetDevice.shell("am start -a android.intent.action.INSERT -t vnd.android.cursor.dir/contact -e name 'Donald Duck' -e phone 555-1234").
所以可见这个方法并没有多少人在用,原因应该是它完全可以用上面介绍的两个方法替代。
(string uri, string action, string data, string mimetype, iterable categories dictionary extras, component component, flags)
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。