MonkeyRunner

包含静态实用程序方法的 monkeyrunner 类。

摘要

方法
void alert (string message, string title, string okTitle)
针对运行当前程序的进程显示一个提醒对话框。
integer choice (string message, iterable choices, string title)
显示一个对话框,其中列出了针对运行当前程序的进程的选项。
void help (string format)
使用指定格式以类似于 Python 的 pydoc 工具的样式显示 monkeyrunner API 引用。
string input (string message, string initialValue, string title, string okTitle, string cancelTitle)
显示一个接受输入的对话框。
void sleep (float seconds)
将当前程序暂停指定的秒数。
MonkeyDevice waitForConnection (float timeout, string deviceId)
尝试在 monkeyrunner 后端与指定的设备或模拟器之间建立连接。

公共方法

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

针对运行当前程序的进程显示一个提醒对话框。该对话框是模态的,因此程序会暂停,直到用户点击该对话框的相应按钮为止。

参数
message 对话框中显示的消息。
title 对话框的标题。默认值为“Alert”。
okTitle 对话框按钮中显示的文本。默认值为“OK”。

integer choice (string message, iterable choices, string title)

显示一个对话框,其中列出了针对运行当前程序的进程的选项。该对话框是模态的,因此程序会暂停,直到用户点击该对话框的其中某个按钮为止。

参数
message 对话框中显示的提示消息。
choices 一个 Python 可迭代对象,其中包含一个或多个显示为字符串的对象。推荐的格式是字符串数组。
title 对话框的标题。默认值为“Input”。
返回
  • 如果用户做出选择并点击“OK”按钮,该方法会返回在可迭代对象中选择的内容(索引从 0 开始)。如果用户点击“Cancel”按钮,该方法会返回 -1。

void help (string format)

使用指定格式以类似于 Python 的 pydoc 工具的样式显示 monkeyrunner API 引用。

参数
format 要在输出中使用的标记格式。可能的值是“text”(对于纯文本)或“html”(对于 HTML)。

string input (string message string initialValue, string title, string okTitle, string cancelTitle)

显示一个接受输入并将其返回给程序的对话框。该对话框是模态的,因此程序会暂停,直到用户点击该对话框的其中某个按钮为止。

该对话框包含两个按钮,其中一个显示 okTitle 值,另一个显示 cancelTitle 值。如果用户点击 okTitle 按钮,系统会返回输入框的当前值。如果用户点击 cancelTitle 按钮,系统会返回空字符串。

参数
message 对话框中显示的提示消息。
initialValue 要在对话框中显示的初始值。默认值为空字符串。
title 对话框的标题。默认值为“Input”。
okTitle okTitle 按钮中显示的文本。默认值为“OK”。
cancelTitle cancelTitle 按钮中显示的文本。默认值为“Cancel”。
返回
  • 如果用户点击 okTitle 按钮,则该方法会返回对话框输入框的当前值。如果用户点击 cancelTitle 按钮,则该方法返回一个空字符串。

void sleep ( float seconds )

将当前程序暂停指定的秒数。

参数
seconds 要暂停的秒数。

MonkeyDevice waitForConnection (float timeout, string deviceId)

尝试在 monkeyrunner 后端与指定的设备或模拟器之间建立连接。

参数
timeout 等待连接的秒数。默认值为无限期等待。
deviceId 一个正则表达式,用于指定设备或模拟器的序列号。有关设备和模拟器序列号的说明,请参阅 Android 调试桥一文。
返回
  • 设备或模拟器的 MonkeyDevice 实例。使用此对象可控制设备或模拟器并与之通信。