用途:Mobilewright 是面向 iOS 与 Android 的移动设备自动化、测试与开发验证框架,风格类似 Playwright。适用于编写移动应用测试(E2E、回归、冒烟)、自动化设备交互(截图、重复任务),以及在开发过程中验证 UI 实现。
主要能力:提供 CLI 命令,包括 npx mobilewright init 初始化配置与示例测试、npx mobilewright doctor 检查环境、npx mobilewright devices 列出设备、npx mobilewright test 运行测试、npx mobilewright screenshot 截图。测试基于 @mobilewright/test,提供 screen、device、bundleId 等 fixture,支持 test.use() 覆盖 bundleId、platform、deviceId、video 等选项。定位器支持 getByTestId、getByRole、getByLabel、getByPlaceholder、getByText、getByType,并有自动等待、重试断言、集合操作、链式查询与等待状态。设备 API 支持应用生命周期、深链、方向、录制与关闭。
使用方式:先运行 npx mobilewright init 生成 mobilewright.config.ts 与示例测试,再用 npx mobilewright doctor 验证环境。编写定位器前应先调用 screen.viewTree() 检查无障碍视图树,不要猜测元素名称。定位器优先级为 testId、role、label、placeholder、text、type。测试中可用 terminateApp 与 launchApp 保证每个用例的干净状态。独立脚本可用 ios.launch 或 android.launch 启动设备,完成后调用 device.close()。
适用场景:移动应用测试、自动化脚本、开发期 UI 验证。
限制:资料未提供收费、价格、平台支持范围、性能效果等具体信息;getByPlaceholder 仅可用于链式 Locator,不能直接用于 Screen;goBack 仅 Android 有效,iOS 为空操作;部分角色映射在 iOS 或 Android 上可能不存在。