Android自动化测试之MonkeyRunner之MonkeyRunner(九)

本文介绍Android自动化测试工具MonkeyRunner的基本用法,包括显示对话框、输入框及选择框的方法,帮助文档的展示方式,以及如何暂停程序和连接设备。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android自动化测试之MonkeyRunner之MonkeyRunner

A monkeyrunner class that contains static utility methods.

Summary


Methods
<nobr>void </nobr> <nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyRunner.html#alert">alert</a></span>(<em>string</em> message,<em>string</em> title,<em>string</em> okTitle)</nobr>
Displays an alert dialog to the process running the current program.
<nobr><em>integer</em> </nobr> <nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyRunner.html#choice">choice</a></span>(<em>string</em> message,<em>iterable</em> choices,<em>string</em> title)</nobr>
Displays a dialog with a list of choices to the process running the current program.
<nobr>void </nobr> <nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyRunner.html#help">help</a></span>(<em>string</em> format)</nobr>
Displays the monkeyrunner API reference in a style similar to that of Python's pydoc tool, using the specified format.
<nobr><em>string</em> </nobr> <nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyRunner.html#input">input</a></span>(<em>string</em> message,<em>string</em> initialValue,<em>string</em> title,<em>string</em> okTitle,<em>string</em> cancelTitle) </nobr>
Displays a dialog that accepts input.
<nobr>void </nobr> <nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyRunner.html#sleep">sleep</a></span>(<em>float</em> seconds)</nobr>
Pauses the current program for the specified number of seconds.
<nobr><code><a href="http://developer.android.com/tools/help/MonkeyDevice.html">MonkeyDevice</a></code></nobr> <nobr><span class="sympad"><a href="http://developer.android.com/tools/help/MonkeyRunner.html#waitForConnection">waitForConnection</a></span>(<em>float</em> timeout,<em>string</em> deviceId)</nobr>
Tries to make a connection between the monkeyrunner backend and the specified device or emulator.

Public Methods


string alert(string message,string title,string okTitle)

Displays an alert dialog to the process running the current program. The dialog is modal, so the program pauses until the user clicks the dialog's button.

Arguments
messageThe message to display in the dialog.
titleThe dialog's title. The default value is "Alert".
okTitleThe text displayed in the dialog button. The default value is "OK".
integer choice(string message,iterable choices,string title)

Displays a dialog with a list of choices to the process running the current program. The dialog is modal, so the program pauses until the user clicks one of the dialog's buttons.

Arguments
messageThe prompt message displayed in the dialog.
choicesA Python iterable containing one or more objects that are displayed as strings. The recommended form is an array of strings.
titleThe dialog's title. The default is "Input".
Returns
  • If the user makes a selection and clicks the "OK" button, the method returns the 0-based index of the selection within the iterable. If the user clicks the "Cancel" button, the method returns -1.
void help(string format)

Displays the monkeyrunner API reference in a style similar to that of Python'spydoc tool, using the specified format.

Arguments
formatThe markup format to use in the output. The possible values are "text" for plain text or "html" for HTML.
string input(string messagestring initialValue,string title,string okTitle,string cancelTitle)

Displays a dialog that accepts input and returns it to the program. The dialog is modal, so the program pauses until the user clicks one of the dialog's buttons.

The dialog contains two buttons, one of which displays the okTitle value and the other the cancelTitle value. If the user clicks the okTitle button, the current value of the input box is returned. If the user clicks the cancelTitle button, an empty string is returned.

Arguments
messageThe prompt message displayed in the dialog.
initialValueThe initial value to display in the dialog. The default is an empty string.
titleThe dialog's title. The default is "Input".
okTitleThe text displayed in the okTitle button. The default is "OK".
cancelTitleThe text displayed in the cancelTitle button. The default is "Cancel".
Returns
  • If the user clicks the okTitle button, then the method returns the current value of the dialog's input box. If the user clicks the cancelTitle button, the method returns an empty string.
void sleep(float seconds )

Pauses the current program for the specified number of seconds.

Arguments
secondsThe number of seconds to pause.
MonkeyDevicewaitForConnection(float timeout,string deviceId)

Tries to make a connection between the monkeyrunner backend and the specified device or emulator.

Arguments
timeoutThe number of seconds to wait for a connection. The default is to wait forever.
deviceIdA regular expression that specifies the serial number of the device or emulator. See the topicAndroid Debug Bridge for a description of device and emulator serial numbers.
Returns
  • A MonkeyDevice instance for the device or emulator. Use this object to control and communicate with the device or emulator.

参考:http://developer.android.com/tools/help/MonkeyRunner.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值