MonkeyRunner
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Class monkeyrunner yang berisi metode utilitas statis.
Ringkasan
Metode |
void
|
alert
(pesan string,
string title,
string okTitle)
Menampilkan dialog peringatan untuk proses yang menjalankan program saat ini.
|
bilangan bulat
|
choice
(pesan string, pilihan
iterable,
judul string)
Menampilkan dialog dengan daftar pilihan untuk proses yang menjalankan program saat ini.
|
void
|
bantuan
(format string)
Menampilkan referensi API monkeyrunner dalam gaya yang mirip dengan alat pydoc Python, yang menggunakan format yang ditentukan.
|
string
|
input
(pesan string,
string initialValue,
string judul,
string okTitle,
string cancelTitle)
Menampilkan dialog yang menerima masukan.
|
void
|
sleep
(float detik)
Menjeda program saat ini selama jumlah detik yang ditentukan.
|
MonkeyDevice
|
waitForConnection
(waktu tunggu float,
string deviceId)
Mencoba membuat koneksi antara backend monkeyrunner dan perangkat
atau emulator yang ditentukan.
|
Metode publik
string
alert
(
pesan string,
judul string,
string okTitle)
Menampilkan dialog peringatan untuk proses yang menjalankan
program saat ini. Dialog adalah modal, sehingga program akan dijeda sampai pengguna mengklik tombol
dialog.
Argumen
message |
Pesan yang akan ditampilkan dalam dialog.
|
title |
Judul dialog. Nilai defaultnya adalah "Alert".
|
okTitle |
Teks yang ditampilkan di tombol dialog. Nilai defaultnya adalah "OK".
|
bilangan bulat
pilihan
(pesan string, pilihan
iterable,
judul string)
Menampilkan dialog dengan daftar pilihan untuk proses yang menjalankan program saat ini. Dialog
adalah modal, sehingga program akan dijeda sampai pengguna mengklik salah satu tombol
dialog.
Argumen
message |
Pesan perintah yang ditampilkan dalam dialog.
|
choices |
Iterable Python yang berisi satu atau beberapa objek yang ditampilkan sebagai string. Bentuk
yang direkomendasikan adalah array string.
|
title
|
Judul dialog. Defaultnya adalah "Input".
|
Return
-
Jika pengguna membuat pilihan dan mengklik tombol "OK", metode akan menampilkan
indeks berbasis 0 dari pemilihan dalam iterable.
Jika pengguna mengklik tombol "Cancel", metode akan menampilkan -1.
Menampilkan referensi API monkeyrunner dalam gaya yang mirip dengan alat pydoc
Python, yang menggunakan format yang ditentukan.
Argumen
format |
Format markup yang akan digunakan dalam output. Nilai yang dimungkinkan adalah "text" untuk teks biasa
atau "html" untuk HTML.
|
Menampilkan dialog yang menerima input dan menampilkannya ke program. Dialog adalah
modal, sehingga program akan dijeda sampai pengguna mengklik salah satu tombol dialog.
Dialog berisi dua tombol, salah satunya menampilkan nilai okTitle
dan yang lainnya menampilkan nilai cancelTitle. Jika pengguna mengklik tombol okTitle,
nilai kotak input saat ini akan ditampilkan. Jika pengguna mengklik tombol
cancelTitle, string kosong akan ditampilkan.
Argumen
message |
Pesan perintah yang ditampilkan dalam dialog.
|
initialValue |
Nilai awal yang akan ditampilkan dalam dialog. Defaultnya adalah string kosong.
|
title |
Judul dialog. Defaultnya adalah "Input".
|
okTitle |
Teks yang ditampilkan di tombol okTitle. Defaultnya adalah "OK".
|
cancelTitle |
Teks yang ditampilkan di tombol cancelTitle. Defaultnya adalah "Cancel".
|
Hasil
-
Jika pengguna mengklik tombol okTitle, metode akan menampilkan nilai
kotak input dialog saat ini. Jika pengguna mengklik tombol cancelTitle, metode akan menampilkan
string kosong.
void
sleep
(
float detik
)
Menjeda program saat ini selama jumlah detik yang ditentukan.
Argumen
detik |
Jumlah detik yang dijeda.
|
MonkeyDevice
waitForConnection
(waktu tunggu float,
string deviceId)
Mencoba membuat koneksi antara backend monkeyrunner
dan perangkat
atau emulator yang ditentukan.
Argumen
timeout |
Jumlah detik untuk menunggu koneksi. Defaultnya adalah menunggu selamanya.
|
deviceId
|
Ekspresi reguler yang menentukan nomor seri perangkat atau emulator. Untuk
mengetahui
deskripsi perangkat dan
nomor seri emulator, lihat topik Android Debug Bridge.
|
Return
-
Instance
MonkeyDevice
untuk perangkat atau emulator. Gunakan objek ini untuk mengontrol dan berkomunikasi dengan
perangkat atau emulator.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-27 UTC."],[],[],null,["# MonkeyRunner\n\nA monkeyrunner class that contains static utility methods.\n\nSummary\n-------\n\n| Methods ||||||||||||\n|------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|---|---|---|---|---|---|---|---|---|\n| void | [alert](#alert) (*string* message, *string* title, *string* okTitle) Displays an alert dialog to the process running the current program. |\n| *integer* | [choice](#choice) (*string* message, *iterable* choices, *string* title) Displays a dialog with a list of choices to the process running the current program. |\n| void | [help](#help) (*string* format) Displays the monkeyrunner API reference in a style similar to that of Python's `pydoc` tool, using the specified format. |\n| *string* | [input](#input) (*string* message, *string* initialValue, *string* title, *string* okTitle, *string* cancelTitle) Displays a dialog that accepts input. |\n| void | [sleep](#sleep) (*float* seconds) Pauses the current program for the specified number of seconds. |\n| ` `[MonkeyDevice](/tools/help/MonkeyDevice)` ` | [waitForConnection](#waitForConnection) (*float* timeout, *string* deviceId) Tries to make a connection between the `monkeyrunner` backend and the specified device or emulator. |\n\nPublic methods\n--------------\n\n#### *string*\nalert\n( *string* message, *string* title, *string* okTitle)\n\n\nDisplays an alert dialog to the process running the current\nprogram. The dialog is modal, so the program pauses until the user clicks the dialog's\nbutton. \n\n##### Arguments\n\n| message | The message to display in the dialog. |\n| title | The dialog's title. The default value is \"Alert\". |\n| okTitle | The text displayed in the dialog button. The default value is \"OK\". |\n|---------|---------------------------------------------------------------------|\n\n#### *integer*\nchoice\n(*string* message, *iterable* choices, *string* title)\n\n\nDisplays a dialog with a list of choices to the process running the current program. The\ndialog is modal, so the program pauses until the user clicks one of the dialog's\nbuttons. \n\n##### Arguments\n\n| message | The prompt message displayed in the dialog. |\n| choices | A Python iterable containing one or more objects that are displayed as strings. The recommended form is an array of strings. |\n| title | The dialog's title. The default is \"Input\". |\n|---------|------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- 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. \n\n#### void\nhelp\n(*string* format)\n\n\nDisplays the monkeyrunner API reference in a style similar to that of Python's\n`pydoc` tool, using the specified format. \n\n##### Arguments\n\n| format | The markup format to use in the output. The possible values are \"text\" for plain text or \"html\" for HTML. |\n|--------|-----------------------------------------------------------------------------------------------------------|\n\n#### *string*\ninput\n(*string* message *string* initialValue, *string* title, *string* okTitle, *string* cancelTitle)\n\n\nDisplays a dialog that accepts input and returns it to the program. The dialog is\nmodal, so the program pauses until the user clicks one of the dialog's buttons.\n\n\nThe dialog contains two buttons, one of which displays the okTitle value\nand the other the cancelTitle value. If the user clicks the okTitle button,\nthe current value of the input box is returned. If the user clicks the cancelTitle\nbutton, an empty string is returned. \n\n##### Arguments\n\n| message | The prompt message displayed in the dialog. |\n| initialValue | The initial value to display in the dialog. The default is an empty string. |\n| title | The dialog's title. The default is \"Input\". |\n| okTitle | The text displayed in the okTitle button. The default is \"OK\". |\n| cancelTitle | The text displayed in the cancelTitle button. The default is \"Cancel\". |\n|--------------|-----------------------------------------------------------------------------|\n\n##### Returns\n\n- 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. \n\n#### void\nsleep\n( *float* seconds )\n\n\nPauses the current program for the specified number of seconds. \n\n##### Arguments\n\n| seconds | The number of seconds to pause. |\n|---------|---------------------------------|\n\n#### `\n`[MonkeyDevice](/tools/help/MonkeyDevice)`\n`\nwaitForConnection\n(*float* timeout, *string* deviceId)\n\n\nTries to make a connection between the `monkeyrunner` backend and the\nspecified device or emulator. \n\n##### Arguments\n\n| timeout | The number of seconds to wait for a connection. The default is to wait forever. |\n| deviceId | A regular expression that specifies the serial number of the device or emulator. See the topic [Android Debug Bridge](/tools/help/adb) for a description of device and emulator serial numbers. |\n|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- A [MonkeyDevice](/tools/help/MonkeyDevice) instance for the device or emulator. Use this object to control and communicate with the device or emulator."]]