MonkeyRunner_monkeyrunner: interacting with the Views
2012-12-13 14:52
375 查看
The time may come when you want your tests to interact with the
Application 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 the
Show 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 using
MonkeyDevice.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 patch
chimpchat to support all of the properties in the different Views.
This approach is AndroidViewClient that you can download and install from
github. 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 example
View.isChecked() or
View.mText())
sending touch events to the Views by simply invoking
View.touch()
The following script is a case of these abilities in action.
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 the
monkeyrunner 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.
转载自:http://dtmilano.blogspot.com/2012/02/monkeyrunner-interacting-with-views.html
Application 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 the
Show 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 using
MonkeyDevice.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 patch
chimpchat to support all of the properties in the different Views.
This approach is AndroidViewClient that you can download and install from
github. 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 example
View.isChecked() or
View.mText())
sending touch events to the Views by simply invoking
View.touch()
The following script is a case of these abilities in action.
#! /usr/bin/env monkeyrunner ''' Copyright (C) 2012 Diego Torres Milano Created on Feb 3, 2012 @author: diego ''' import re import sys import os # this must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails try: 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 ViewClient from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice # Displayed com.android.development/.DevelopmentSettings: +379ms package = 'com.android.development' activity = '.DevelopmentSettings' componentName = package + "/" + activity device = 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 the
monkeyrunner 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.
转载自:http://dtmilano.blogspot.com/2012/02/monkeyrunner-interacting-with-views.html
相关文章推荐
- MonkeyRunner_monkeyrunner: interacting with the Views
- iOS-Best Practices for Interacting with a Remote Peripheral Device(API Reference) the sixth part
- [译]Objective-C Runtime Programming Guide - Interacting with the Runtime (一)
- The study of chapter 13 in programming windows with mfc-printing with document and views
- Less copies in Python with the buffer protocol and memoryviews
- android tab with interacting map and list views
- 官方文档 恢复备份指南四 Starting and Interacting with the RMAN Client
- Interacting with the User in a Service
- 官方文档 恢复备份指南四 Starting and Interacting with the RMAN Client
- Interacting with the Runtime
- Objective-C 运行时编程指南 之 Interacting with the Runtime
- Interacting with the Master Page from the Content Page
- 与运行时交互(Interacting with the Runtime)
- 物联网与嵌入式系统概论-week2-Embedded Systems-Lesson3: Interacting with the Physical World
- SLF4J: The requested version 1.5.8 by your slf4j binding is not compatible with [1.6] SLF4J: See htt
- AlphaGo论文的译文,用深度神经网络和树搜索征服围棋:Mastering the game of Go with deep neural networks and tree search
- Effects with the Pixel Bender Toolkit – Part 8: Controlling the displacement filter with mouse positioning
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- Embedded binary is not signed with the same certificate as the parent app
- 内部类的使用问题No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclo