运行 Robo 脚本 (iOS+)
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本文档介绍了如何使用 Robo 脚本,这些脚本是一些测试,用于自动执行移动应用的手动质量检查任务,并有助于实现持续集成 (CI) 和发布前测试策略。例如,您可以使用 Robo 脚本测试常见的用户操作历程或提供特定的界面 (UI) 输入,例如用户名和密码。Robo 脚本是 Robo 测试的一项功能。
Robo 脚本使用 Robo 测试作为测试引擎。在最基本的形式中,Robo 脚本由一系列界面操作(例如输入文本“username”,然后点按“确定”按钮)组成。Robo 脚本还可包含等待元素显示、点按元素内特定位置以及执行 Android 调试桥 (adb
) shell 命令等操作。
与传统测试框架相比,Robo 脚本具有以下优势:
功能
|
说明 |
非常稳健 |
Robo 脚本可以容忍不同应用版本间的重大结构和行为差异以及应用不稳定性。 |
开放 |
Robo 脚本执行完成后,基础 Robo 测试可以接管并继续测试应用。这种持续的测试方式可实现几个关键用例。例如,您可以通过执行自定义登录流程,使用 Robo 脚本让应用处于特定状态。 |
可记录 |
您无需手动编写 Robo 脚本。您可以使用 Android Studio 中的 Robo 脚本记录器记录这些脚本。创建或修改 Robo 脚本通常不需要具备任何移动开发知识。 |
灵活
|
Robo 脚本可以与游戏中常见的非原生界面元素进行交互。 |
Robo 脚本会在 Robo 测试期间有条件地触发,这使得用户可以为实现更大的覆盖率或针对特定功能而增强 Robo 的行为。与传统测试框架相比,Robo 脚本提供以下支持:
- 各种触发条件,例如,特定应用软件包名称有效(或无效),亦或有特定元素显示(或未显示)在屏幕上。
- 执行控制措施,例如,执行次数上限、优先级和相关抓取阶段。
- 非常规操作类型(基于条件的操作、元素忽略操作、屏幕关闭操作)。
我们建议您尽可能使用 Robo 脚本,因为它们易于维护。例如,您可以使用 Robo 脚本执行以下操作:
- 探索重要的工作流,深入应用功能的核心。例如,您可以执行登录操作、在首次启动后设置应用的状态,以及注册新用户。
- 让 Robo 专注于应用的特定部分,以便充分利用 Robo 测试时间。Robo 脚本会指导 Robo 测试到达应用的相关部分,在该部分中,Robo 测试会继续执行全自动抓取操作。
- 让应用处于特定状态或进入特定屏幕以执行分析,例如分析应用内消息功能、隐私权政策屏幕或游戏的特定关卡。
- 在 Robo 脚本执行完成后,执行端到端插桩测试(可选择是否继续执行 Robo 测试的全自动抓取操作)。
您可以使用更高级的 Robo 脚本功能执行以下操作:
- 在 Robo 开始抓取被测应用之前或完成抓取之后执行操作,例如在抓取之前清理被测应用数据或更改设备设置。
- 更改 Robo 在抓取过程中方方面面的行为,尤其是以下操作:
- 指示 Robo 忽略某些界面 widget 或应用屏幕。
- 在 Robo 从特定屏幕回溯时为其提供可执行的自定义操作。
- 指示 Robo 每当在抓取过程中遇到特定应用屏幕时执行特定操作。
- 完全自定义 Robo 的抓取方式。例如,您可以组合使用基于条件的操作和无条件操作,使被测应用在整个抓取过程中始终处于后台,同时执行各种设备操作并关闭屏幕上显示的任何弹出式对话框。
请注意,Robo 脚本不会取代所有类型的测试。您仍然需要通过单元测试来捕获应用中的低级别逻辑 bug;这些测试通常不需要 Android 或 iOS 环境。我们建议您使用定向插桩测试来补充 Robo 脚本测试。定向插桩测试可以包含有关业务逻辑的特定详细断言,而这些断言最适合通过代码来表达。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-16。
[null,null,["最后更新时间 (UTC):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)."]]