Skip to content

[Rust][go-ios] WebDriverKeeper3 — WDA 保活(无 xcodebuild) #38

@nzcv

Description

@nzcv

[Rust][go-ios] WebDriverKeeper3 — WDA 保活(无 xcodebuild)

在 wda 综合仓库中实现 WebDriverKeeper3:用 Rust + go-ios 替代 xcodebuild,完成 WebDriverAgent 长时间保活;代码注释使用英文。

背景

仓库内已有两套基于 xcodebuild 的保活方案:

方案 语言 编译/启动
WebDriverKeeper (WDK1) Python xcodebuild build-for-testing + test-without-building
WebDriverKeeper2 (WDK2) Swift 同上
WebDriverKeeper3 (WDK3) Rust go-ios install + runwda,无 xcodebuild

WDK3 的设计目标(见根目录 README.md):

  1. 不再采用 xcodebuild
  2. 基于 Rust/go-ios 实现 WDA 保活
  3. 注释使用英文

实现架构

WebDriverKeeper3/
├── Cargo.toml
├── config.example.yaml
├── README.md
└── src/
    ├── main.rs      # CLI: wdk3
    ├── config.rs    # YAML 配置
    ├── devices.rs   # USB 设备发现(xctrace → go-ios list)
    ├── health.rs    # HTTP GET /status 探活
    ├── ios.rs       # go-ios CLI 封装
    ├── installer.rs # ios install(设备无 WDA 时)
    ├── runner.rs    # ios runwda 后台启动 + PID 管理
    └── keeper.rs    # 巡检循环编排

保活流程

  1. 发现 USB 已连接真机(优先 xctrace list devices,兜底 ios list
  2. 与配置中 devices[](含 WiFi IP)取交集
  3. 对每台设备请求 http://<ip>:<port>/status
  4. 未就绪时:ios install(可选,需 wda.app_path)→ ios runwda → 轮询直到 ready
  5. poll_interval 重复

与 WDK1/WDK2 的关键差异

能力 WDK1/WDK2 WDK3
编译 WDA xcodebuild 外部一次性构建(Xcode/CI)
安装 xcodebuild 顺带 ios install --path=<.app|.ipa>
启动 xcodebuild test-without-building ios runwda
探活 WiFi /status 相同
设备注册 Python 版可 xcodebuild 按设备注册 需预签名包 / 手动注册 UDID

配置示例

log_dir: .wdk3/logs
poll_interval: 30
ready_timeout: 120
status_timeout: 5
default_port: 8100
ios_binary: ""   # 空则自动检测 go-ios / ios

wda:
  bundle_id: "com.example.WebDriverAgentRunner"
  # test_runner_bundle_id 默认 <bundle_id>.xctrunner
  xctest_config: "WebDriverAgentRunner.xctest"
  app_path: ""   # 预签名 .app 或 .ipa,设备无 WDA 时安装

devices:
  - udid: "00008030-000000000000000E"
    ip: "192.168.1.50"

若已有 WDK1 编译产物,可复用 Runner.app:

wda:
  bundle_id: "com.rm42.facebook.WebDriverAgentRunner"
  app_path: "../WebDriverKeeper/.wdk/derived_data/Build/Products/Debug-iphoneos/WebDriverAgentRunner-Runner.app"

使用方式

cd WebDriverKeeper3
cp config.example.yaml config.yaml
cargo build --release

./target/release/wdk3 -c config.yaml          # 常驻巡检
./target/release/wdk3 -c config.yaml --once   # 单轮
./target/release/wdk3 -c config.yaml --force-install  # 强制重装 WDA

日志与 PID:.wdk3/logs/<udid>.log.wdk3/logs/<udid>.pid

go-ios 启动命令(内部等价)

ios runwda \
  --bundleid=<bundle_id>.xctrunner \
  --testrunnerbundleid=<bundle_id>.xctrunner \
  --xctestconfig=WebDriverAgentRunner.xctest \
  --log-output=.wdk3/logs/<udid>.log \
  --udid=<udid> \
  --env USE_PORT=8100

注意事项

  1. iOS 17+:可能需要先 ios tunnel start(管理员权限),详见 go-ios
  2. 无 xcodebuild 自动 provisioning:新设备需事先在 Apple Developer 注册 UDID,或使用已包含该设备的签名包
  3. WiFi IP 必填:探活仍走 http://device_ip:port/status,与 WDK1/WDK2 相同

依赖

  • Rust 2021 edition
  • crates: clap, serde/serde_yaml, reqwest (blocking), tracing, regex, anyhow
  • 运行时:go-iosios 在 PATH

推荐组合

  • 日常保活(Mac + 已签名 WDA):WDK3 + 预构建 Runner.app + WiFi 探活
  • 需 xcodebuild 自动编译/按设备注册:继续用 WDK1(Python)
  • iOS 17+ 长跑:WDK3 前先确保 ios tunnel start 稳定运行

后续可扩展

  • 从 WDK1 config.yaml 自动生成 WDK3 配置
  • iOS 17+ tunnel 自动检测与拉起
  • 多设备 tunnel 管理

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions