patrol-setup

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Patrol setup

Patrol 配置

Get a first Patrol test passing on an Android emulator. Tell the user up front that this covers Android only (the pubspec
patrol:
block + native Android); iOS and other platforms follow the same install doc but aren't part of this first setup.
This skill is the ordered process and the gotchas; the canonical docs are the source of truth for versions, native config, and code — follow them at each step instead of guessing:
让首个Patrol测试在Android模拟器上运行通过。提前告知用户,本文仅覆盖Android平台(包括pubspec中的
patrol:
块 + 原生Android配置);iOS及其他平台的配置流程与本文一致,但不在本次初始配置范围内。
本技能涵盖了有序的操作流程及常见陷阱;官方文档是版本、原生配置及代码的权威来源——请在每个步骤中遵循官方文档指引,而非自行猜测:

1. Configure Patrol

1. 配置Patrol

Follow the Setup steps, deep-linking to the relevant point:
遵循设置步骤,可点击链接跳转到对应细节:

2. Write a first minimal test

2. 编写首个最简测试

Follow write your first test for the current API: https://patrol.leancode.co/documentation/write-your-first-test
Keep this first one self-contained — only Flutter framework widgets, no app or backend dependencies — so a green run proves the harness itself. Place it in
patrol_test/
(or the configured
test_directory
).
遵循编写首个测试文档使用当前API: https://patrol.leancode.co/documentation/write-your-first-test
确保首个测试独立运行——仅使用Flutter框架组件,不依赖应用或后端服务——这样测试通过即可证明测试环境本身正常。将测试文件放在
patrol_test/
目录下(或配置好的
test_directory
目录)。

3. Ignore the bundle and secrets

3. 忽略生成包与敏感信息

Gitignore
test_bundle.dart
(generated by Patrol) and
.patrol.env
(your dart-defines, often secrets) per the Setup section: https://patrol.leancode.co/documentation#setup
根据设置部分的指引,将
test_bundle.dart
(由Patrol生成)和
.patrol.env
(你的dart-defines,通常包含敏感信息)添加到.gitignore中: https://patrol.leancode.co/documentation#setup

4. Run on an emulator

4. 在模拟器上运行测试

Boot an Android emulator and wait for boot to fully complete before running — a test launched mid-boot fails. Then run the single test with
patrol test
. A green run confirms the setup.
启动Android模拟器,等待完全启动后再运行测试——在启动过程中运行测试会失败。然后使用
patrol test
命令运行单个测试。测试通过即表示配置完成。

Gotchas

常见陷阱

  • MainActivity
    cannot be resolved (Java)
    — set the
    MainActivityTest.java
    package
    to the app's
    applicationId
    .
  • Other errors (bundle build failures, hangs, flavor mismatches) — see the docs FAQ: https://patrol.leancode.co/documentation#faq
  • MainActivity
    无法解析(Java)
    ——将
    MainActivityTest.java
    中的
    package
    设置为应用的
    applicationId
  • 其他错误(包构建失败、卡顿、构建变体不匹配)——请参考文档FAQ:https://patrol.leancode.co/documentation#faq

Next: Patrol MCP (optional)

下一步:Patrol MCP(可选)

Once the setup is green, mention to the user that Patrol MCP exists and can be set up on request — it lets an AI agent run tests, capture screenshots, read the native UI tree, and drive an interactive session. Let the user decide; if they want it, follow the README: https://pub.dev/packages/patrol_mcp
配置完成并测试通过后,可告知用户Patrol MCP的存在,可按需配置——它支持AI Agent运行测试、捕获截图、读取原生UI树,并驱动交互式会话。由用户决定是否配置;若需要,请遵循README:https://pub.dev/packages/patrol_mcp