執行 Robo 指令碼 (iOS 以上版本)
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本文說明如何使用 Robo 指令碼。這類測試可自動執行行動應用程式的手動 QA 工作,並啟用持續整合 (CI) 和發布前測試策略。舉例來說,您可以使用 Robo 指令碼測試一般使用者歷程,或提供特定使用者介面 (UI) 輸入內容,例如使用者名稱和密碼。Robo 指令碼是 Robo 測試的功能。
Robo 指令碼會使用 Robo 測試做為測試引擎。最基本的 Robo 指令碼是由一連串的 UI 動作組成,例如輸入文字「使用者名稱」,然後輕觸「確定」按鈕。Robo 指令碼也可以包含等待元素顯示、輕觸元素內的特定點,以及執行 Android Debug Bridge (adb
) 殼層指令等動作。
相較於傳統測試架構,Robo 指令碼有以下優點:
功能
|
說明 |
高度穩健
|
Robo 腳本可容許應用程式版本之間存在顯著的結構和行為差異,以及應用程式不穩定。 |
開放式問題
|
Robo 指令碼完成後,基本 Robo 測試可以接手並繼續測試應用程式。這種持續測試方法可支援多種重要用途。舉例來說,您可以透過 Robo 指令碼執行自訂登入流程,讓應用程式進入特定狀態。 |
Recordable
|
您不必手動編寫 Robo 指令碼,您可以使用 Android Studio 中的 Robo 指令碼記錄器記錄這些指令碼。建立或修改 Robo 指令碼通常不需要任何行動開發知識。 |
彈性
|
Robo 指令碼可與遊戲中常見的非原生 UI 元素互動。
|
Robo 測試期間會視情況觸發 Robo 指令碼,讓使用者擴增 Robo 的行為,通常是為了提高涵蓋範圍或鎖定特定功能。與傳統測試架構不同,Robo 指令碼支援下列項目:
- 各種觸發條件,例如特定應用程式套件名稱是否處於啟用狀態,或特定元素是否顯示在畫面上。
- 執行控制項,例如執行次數上限、優先順序、相關檢索階段。
- 非傳統動作類型 (條件式、忽略元素、關閉畫面)。
建議您盡可能使用 Robo 腳本,因為這類腳本維護起來毫不費力。舉例來說,你可以使用 Robo 指令碼執行下列操作:
- 瀏覽重要工作流程,瞭解應用程式的核心功能。
舉例來說,您可以登入、在首次啟動後設定應用程式狀態,以及註冊新使用者。
- 讓 Robo 專注於應用程式的特定部分,充分利用 Robo 測試時間。Robo 指令碼會引導 Robo 測試前往應用程式的相關部分,然後 Robo 測試會繼續執行全自動檢索。
- 將應用程式帶入特定狀態或畫面進行分析,例如分析應用程式內訊息、隱私權政策或遊戲的特定關卡。
- 執行端對端插樁測試,可選擇是否使用 Robo 測試,在 Robo 指令碼完成後,繼續進行全自動檢索。
使用更多進階 Robo 指令碼功能,執行下列操作:
- 在 Robo 開始檢索受測應用程式之前或檢索完成後執行動作,例如在檢索前清除受測應用程式資料,或變更裝置設定。
- 在檢索期間變更機器人行為,特別是:
- 讓 Robo 忽略某些 UI 小工具或應用程式畫面。
- 為 Robo 提供自訂動作,以便在從特定畫面返回時執行。
- 在檢索期間遇到特定應用程式畫面時,讓 Robo 執行特定動作。
- 全面自訂 Robo 執行檢索的方式。舉例來說,您可以結合使用條件式和非條件式動作,在整個檢索過程中讓受測應用程式保持在背景執行,同時執行裝置操作並關閉過程中出現的任何彈出式對話方塊。
請注意,Robo 指令碼無法取代所有類型的測試。您仍需進行單元測試,才能找出應用程式中的低階邏輯錯誤;這類測試通常不需要 Android 或 iOS 環境。建議您搭配使用 Robo 指令碼測試和目標插樁測試,針對業務邏輯進行特定且詳細的斷言,而這類斷言最適合以程式碼表示。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-16 (世界標準時間)。
[null,null,["上次更新時間:2025-08-16 (世界標準時間)。"],[],[],null,["\u003cbr /\u003e\n\nThis document describes how to use *Robo scripts* , which are tests that automate\nmanual QA tasks for mobile apps, and enable continuous integration (CI) and\npre-launch testing strategies. For example, you can use Robo scripts to test a\ncommon user journey or provide specific user interface (UI) input, like a\nusername and password. Robo scripts are a feature of [Robo\ntest](/docs/test-lab/ios/robo-ux-test).\n\nRobo scripts use [Robo test](/docs/test-lab/android/robo-ux-test)\nas the test engine. In its most basic form, a Robo script consists of a\nsequence of UI actions like *enter text 'username'* and\nthen *tap the OK button* . Robo scripts can also include actions like waiting\nfor an element to appear, tapping at a specific point within an element, and\nexecuting Android Debug Bridge (`adb`) shell commands.\n\nRobo scripts have the following advantages over traditional testing frameworks:\n\n|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Capability** | **Description** |\n| Highly robust | Robo scripts can tolerate significant structural and behavioral differences between app versions and app flakiness. |\n| Open-ended | After a Robo script completes, the base Robo test can take over and continue testing the app. This continued testing approach enables several key use cases. For example, you can use a Robo script to bring an app into a particular state by performing a custom sign-in flow. |\n| Recordable | You don't need to code Robo scripts manually. They can be recorded using the Robo script recorder in Android Studio. Creating or modifying Robo scripts typically doesn't require any knowledge of mobile development. |\n| Flexible | Robo scripts can interact with non-native UI elements that are common in games. |\n\nRobo scripts are conditionally triggered during a Robo test, which lets users\naugment Robo's behavior - typically to achieve greater coverage or target\nspecific functionality. In contrast to traditional testing frameworks,\nRobo scripts support the following:\n\n- Various triggering conditions, for example, a particular app package name being active (or not) or a specific element being displayed on the screen (or not).\n- Execution controls, for example, a maximum number of executions, priority, relevant crawl stage.\n- Unconventional action types (conditional, element-ignoring, screen-closing).\n\nWe recommend that you use Robo scripts whenever possible because they can be\nmaintained effortlessly. For example, you can use a Robo script to do the\nfollowing:\n\n- Navigate significant workflows to get to the core of an app's functionality. For example, you can perform a sign-in, set up an app's state after the first launch, and register a new user.\n- Focus Robo on a particular part of an app to get the most out of Robo test time. Robo script guides Robo test to reach the relevant part of an app, where Robo test resumes a fully automated crawl.\n- Bring an app into a specific state or screen to perform an analysis, for example, to analyze an in-app message, privacy policy, or specific level of a game.\n- Perform an end-to-end instrumentation test, with or without Robo test resuming a fully automated crawl after the Robo script is complete.\n\nUse more advanced Robo script features to do the following:\n\n- Perform actions before Robo starts crawling the app-under-test or after a crawl is finished, for example, clean the app-under-test data before a crawl, or change device settings.\n- Change aspects of Robo behavior during a crawl, in particular:\n - Make Robo ignore some UI widgets or app screens.\n - Provide a custom action for Robo to perform when backtracking from a particular screen.\n - Make Robo perform specific actions whenever a particular app screen is encountered during a crawl.\n- Completely customize how Robo performs a crawl. For example, use a combination of conditional and non-conditional actions to keep the app-under-test in the background throughout the crawl, while performing device manipulations and dismissing any popup dialogs that appear along the way.\n\nKeep in mind that Robo scripts don't replace all kinds of tests. You still\nneed unit tests to catch low-level logic bugs in your app; these tests\ntypically don't require an Android or iOS environment. We recommend that you\nsupplement Robo script tests with targeted instrumentation tests that can have\nspecific, detailed assertions about business logic, which are best expressed\nin code.\n\nNext steps\n\n- To learn about Robo scripts structure, capabilities, usage, and actions, see\n the [Robo scripts reference guide](/docs/test-lab/android/robo-scripts-reference#ios-support-for-robo-scripts).\n\n- [Run a Robo test](/docs/test-lab/ios/robo-ux-test)."]]