MonkeyRunner_monkeyrunner: interacting with the Views
来源:互联网 发布:dash api for windows 编辑:程序博客网 时间:2024/05/20 06:40
The time may come when you want your tests to interact with theApplication Under Test (AUT) in a more clever way than just guessing the View's coordinates on the screen and sending the events.
Furthermore, this is sometimes not possible at all because in order to send the events you may need to obtain some View state. Let me give you an example to illustrate this and if you want you can try to solve it using monkeyrunner.
We can use Development Settings as our AUT and our intention could be to activate theShow running processes and Immediately destroy activities settings.
As we may accustom to do, we can obtain the coordinates of these Views on the screen and send the corresponding touch events usingMonkeyDevice.touch() as usual. Sonner or later, maybe sooner, we will discover that because these settings are persistent we should know the state before sending the event, otherwise we will be changing its state other than just enabling this settings as is this example's intention.
We introduced a way of doing things like that in
Automated Android testing using Sikuli using visual comparison and obtaining properties like the text in EditText's in monkeyrunner: testing views properties (which depends on a patch to chimpchat that has not yet been approved) but now we are craving for a more general approach unless we had the intention to patchchimpchat to support all of the properties in the different Views.
Once we run this script against a running emulator or device we will be able to see how the settings are enabled.
Furthermore, this is sometimes not possible at all because in order to send the events you may need to obtain some View state. Let me give you an example to illustrate this and if you want you can try to solve it using monkeyrunner.
We can use Development Settings as our AUT and our intention could be to activate theShow running processes and Immediately destroy activities settings.
As we may accustom to do, we can obtain the coordinates of these Views on the screen and send the corresponding touch events usingMonkeyDevice.touch() as usual. Sonner or later, maybe sooner, we will discover that because these settings are persistent we should know the state before sending the event, otherwise we will be changing its state other than just enabling this settings as is this example's intention.
We introduced a way of doing things like that in
Automated Android testing using Sikuli using visual comparison and obtaining properties like the text in EditText's in monkeyrunner: testing views properties (which depends on a patch to chimpchat that has not yet been approved) but now we are craving for a more general approach unless we had the intention to patchchimpchat to support all of the properties in the different Views.
This approach is AndroidViewClient that you can download and install fromgithub. Still has its rough edges but I wanted to show its functionality here and be open to comments.
AndroidViewClient adds to monkeyrunner the ability of
- finding Views by ID, very much like you normally do in your Android Activity (using ViewClient.findViewById())
- obtaining the value for almost any of the Views properties (using for exampleView.isChecked() orView.mText())
- sending touch events to the Views by simply invokingView.touch()
The following script is a case of these abilities in action.
#! /usr/bin/env monkeyrunner'''Copyright (C) 2012 Diego Torres MilanoCreated on Feb 3, 2012@author: diego'''import reimport sysimport os# this must be imported before MonkeyRunner and MonkeyDevice,# otherwise the import failstry: ANDROID_VIEW_CLIENT_HOME = os.environ['ANDROID_VIEW_CLIENT_HOME']except KeyError: print >>sys.stderr, "%s: ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment" % __file__ sys.exit(1)sys.path.append(ANDROID_VIEW_CLIENT_HOME + '/src')from com.dtmilano.android.viewclient import ViewClientfrom com.android.monkeyrunner import MonkeyRunner, MonkeyDevice# Displayed com.android.development/.DevelopmentSettings: +379mspackage = 'com.android.development'activity = '.DevelopmentSettings'componentName = package + "/" + activitydevice = MonkeyRunner.waitForConnection(60, "emulator-5554")if not device: raise Exception('Cannot connect to device')device.startActivity(component=componentName)MonkeyRunner.sleep(5)vc = ViewClient(device)vc.dump()showCpu = vc.findViewById("id/show_cpu")showLoad = vc.findViewById("id/show_load")alwaysFinish = vc.findViewById("id/always_finish")if not showLoad.isChecked(): showLoad.touch()if not alwaysFinish.isChecked(): alwaysFinish.touch()if not showCpu.isChecked(): # WARNING: Show CPU usage is de-activated as soon as it's activated, that's why it seems it # is never set showCpu.touch()
Once we run this script against a running emulator or device we will be able to see how the settings are enabled.
Moreover, if you run the script again you will see how the settings remain unchanged.
AndroidViewClient is a work in progress but it is already useful for many cases where themonkeyrunner scripts are not enough or where the complexity of achieving the desired goals is too high.
Give AndroidViewClient a try, share your comments, suggestions, patches and scripts here to help improve it.
- MonkeyRunner_monkeyrunner: interacting with the Views
- MonkeyRunner_monkeyrunner: interacting with the Views
- Interacting with the Runtime
- android tab with interacting map and list views
- MonkeyRunner_monkeyrunner: testing views properties
- Interacting with the User in a Service
- WordPress Essentials: Interacting With The WordPress Database
- 与运行时交互(Interacting with the Runtime)
- INTERACTING WITH FSDMGR(转)
- Interacting with Linknx
- Interacting with Other Apps
- Interacting with Objective-C APIs
- android-Interacting with Other Apps
- Interacting with Other Apps笔记
- 与模拟的硬件按键交互(Interacting with the Simulated Hardware Keys)
- 官方文档 恢复备份指南四 Starting and Interacting with the RMAN Client
- [译]Objective-C Runtime Programming Guide - Interacting with the Runtime (一)
- 物联网与嵌入式系统概论-week2-Embedded Systems-Lesson3: Interacting with the Physical World
- VC在文件中写入换行符和制表符
- AIX 5L 内存性能优化,第 1 部分: AIX Version 5.3 中内存的概述以及内存参数的优化
- WPF数据绑定之4种绑定模式
- linux下用rman恢复数据库
- AIX 5L 内存性能优化,第 2 部分:
- MonkeyRunner_monkeyrunner: interacting with the Views
- JavaScript入门之二:Js基本事件,表单控制
- ThinkPHP移植到另一台电脑后验证码显示不了
- FastDFS下载文件测试 ./fdfs_test %FastDFS%/conf/client.conf download (version:3.11)
- ArcGIS 10.1中的Desktop连接ArcSDE——以Oracle为例
- Skelta BPM.NET有效提升企业效率
- 给点云添加颜色
- Microsoft Visual Studio has encountered a problem and needs to close 解决办法
- java上机 第五周 任务5 封装一个矩阵类