MonkeyDevice函数
来源:互联网 发布:制作毕业纪念册软件 编辑:程序博客网 时间:2024/05/22 02:06
A monkeyrunner class that represents a device or emulator accessible by the workstation runningmonkeyrunner
.
This class is used to control an Android device or emulator. The methods send UI events, retrieve information, install and remove applications, and run applications.
You normally do not have to create an instance of MonkeyDevice
. Instead, you useMonkeyRunner.waitForConnection()
to create a new object from a connection to a device oremulator. For example, instead ofusing:
newdevice = MonkeyDevice()
you would use:
newdevice = MonkeyRunner.waitForConnection()
Summary
type
argument ofpress()
ortouch()
to send a DOWN event.stringUPUse this with the type
argument ofpress()
ortouch()
to send an UP event.stringDOWN_AND_UPUse this with the type
argument ofpress()
ortouch()
to send a DOWN event immediately followed by an UP event.adb shell getprop <key>. This is provided for use by platform developers.
adb
shell command and returns the result, if any.MonkeyImage
MonkeyImage
object containing a screen capture of the current display. press()
for each keycode inmessage
using the key event type DOWN_AND_UP
. Constants
string DOWN
press()
ortouch()
value. Specifies that a DOWN event type should be sent to the device, corresponding to pressing down on a key or touching the screen.
string UP
press()
ortouch()
value. Specifies that an UP event type should be sent to the device, corresponding to releasing a key or lifting up from the screen.
string DOWN_AND_UP
press()
,touch()
ortype()
value. Specifies that a DOWN event type followed by an UP event type should be sent to the device, corresponding to typing a key or clicking the screen.
Public Methods
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. SeeIntent
for more information about the arguments.
Arguments
Intent.setData()
).Intent.setAction()
).Intent.setData()
).Intent.setType()
).Intent.addCategory()
).Intent.putExtra()
for an example).The key for each dictionary item should be a string. The item's value can be any simple or structured data type.
ComponentName
). Using this argument will direct the Intent to a specific class within a specific Android package.Intent.setFlags()
).void drag( tuple start, tuple end, float duration,integer steps)
Simulates a drag gesture (touch, hold, and move) on this device's screen.
Arguments
object getProperty(string key)
Given the name of a system environment variable, returns its value for this device.
Arguments
Returns
- The value of the variable. The data format varies according to the variable requested.
object getSystemProperty(string key)
Synonym for getProperty()
.
Arguments
Returns
- The value of the variable. The data format varies according to the variable requested.
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.
Arguments
.apk
file to install.dictionary instrument( string className, dictionary args)
Runs the specified component with 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.
Use this method to start a test case that uses one of Android's test case classes. SeeTesting Fundamentals to learn more about unit testing with the Android testing framework.
Arguments
.apk
file on this device, and classname is the class name of an Android component (Activity, ContentProvider, Service, or BroadcastReceiver) in that file. Both packagename and classname must be fully qualified. SeeComponentName
for more details.Returns
A dictionary containing the component's output. The contents of the dictionary are defined by the component itself.
If you use
InstrumentationTestRunner
as the class name in the componentName argument, then the result dictionary contains the single key "stream". The value of "stream" is a string containing the test output, as ifInstrumentationTestRunner
was run from the command line. The format of this output is described inTesting in Other IDEs.
void press(string name, integer type)
Sends the key event specified by type
to the key specified by keycode
.
Arguments
KeyEvent
for a list of keycode names. Use the keycode name, not its integer value.DOWN
,UP
, andDOWN_AND_UP
.void reboot(string bootloadType)
Reboots this device into the bootloader specified by bootloadType
.
Arguments
void removePackage(string package)
Deletes the specified package from this device, including its data and cache.
Arguments
.apk
file on this device.object shell(string cmd)
Executes an adb
shell command and returns the result, if any.
Arguments
adb
shell. The form of these commands is described in the topicAndroid Debug Bridge.Returns
- The results of the command, if any. The format of the results is determined by the command.
void startActivity( string uri, string action, string data,string mimetype, iterable categories dictionary extras,component component, iterable flags)
Starts an Activity on this device by sending an Intent constructed from the supplied arguments.
Arguments
Intent.setData()
).Intent.setAction()
).Intent.setData()
).Intent.setType()
).Intent.addCategory()
).Intent.putExtra()
for an example).The key for each dictionary item should be a string. The item's value can be any simple or structured data type.
ComponentName
). Using this argument will direct the Intent to a specific class within a specific Android package.Intent.setFlags()
).MonkeyImage
takeSnapshot ()
Captures the entire screen buffer of this device, yielding a screen capture of the current display.
Returns
- A MonkeyImage object containing the image of the current display.
void touch( integer x, integer y, string type)
Sends a touch event specified by type to the screen location specified by x and y.
Arguments
DOWN
,UP
, andDOWN_AND_UP
.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 inmessage
using the key event type DOWN_AND_UP
.
Arguments
void wake()
Wakes the screen of this device.
Appendix
build
board
Code name for the device's system boardSee Build
brand
The carrier or provider for which the OS is customized.device
The device design name.fingerprint
A unique identifier for the currently-running build.host
ID
A changelist number or label.model
The end-user-visible name for the device.product
The overall product name.tags
Comma-separated tags that describe the build, such as "unsigned" and "debug".type
The build type, such as "user" or "eng".user
CPU_ABI
The name of the native code instruction set, in the form CPU type plus ABI convention.manufacturer
The product/hardware manufacturer.version.incremental
The internal code used by the source control system to represent this version of the software.version.release
The user-visible name of this version of the software.version.sdk
The user-visible SDK version associated with this version of the OS.version.codename
The current development codename, or "REL" if this version of the software has been released.display
width
The device's display width in pixels.See DisplayMetrics
for details.height
The device's display height in pixels.density
The logical density of the display. This is a factor that scales DIP (Density-Independent Pixel) units to the device's resolution. DIP is adjusted so that 1 DIP is equivalent to one pixel on a 160 pixel-per-inch display. For example, on a 160-dpi screen, density = 1.0, while on a 120-dpi screen, density = .75.The value does not exactly follow the real screen size, but is adjusted to conform to large changes in the display DPI. Seedensity
for more details.
am.current
package
The Android package name of the currently running package.The am.current
keys return information about the currently-running Activity.action
The current activity's action. This has the same format as the name
attribute of theaction
element in a package manifest.comp.class
The class name of the component that started the current Activity. See comp.package
for more details.comp.package
The package name of the component that started the current Activity. A component is specified by a package name and the name of class that the package contains.data
The data (if any) contained in the Intent that started the current Activity.categories
The categories specified by the Intent that started the current Activity.clock
realtime
The number of milliseconds since the device rebooted, including deep-sleep time.See SystemClock
for more information.uptime
The number of milliseconds since the device rebooted, not including deep-sleep timemillis
current time since the UNIX epoch, in milliseconds.- MonkeyDevice函数
- MonkeyDevice API 教程
- monkeyDevice常用API
- Android自动测试之MonkeyRunner之MonkeyDevice
- MonkeyRunner_MonkeyRunner,MonkeyDevice,MonkeyImage可以调用的方法
- Android自动测试之MonkeyRunner之MonkeyDevice
- EasyMonkeyDevice vs MonkeyDevice&HierarchyViewer API Mapping Matrix
- MonkeyRunner—API篇之MonkeyDevice
- Android自动化测试之MonkeyRunner之MonkeyDevice(八)
- 第3章2节《MonkeyRunner源码剖析》脚本编写示例: MonkeyDevice API使用示例(原创)
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- ios学习--openURL的使用方法
- js技巧
- oracle 字符串列转行
- MFC ListControl用法总结
- clk_get函数实现,Linux内核时钟框架
- MonkeyDevice函数
- vim 插件
- 完美解读Linux中文件系统的目录结构
- Git 1.8.0 改进内容
- 循环获取GridView中的Textbox内的值
- u-boot分析——struct gd_t与struct bd_t
- 谐振电路及品质因数(一)
- 函数库regexec匹配正则表达式
- MonkeyImage函数