用途:面向 React Native 应用的 Detox 端到端(E2E)测试与移动自动化,提供测试编写、配置与调试的实践指导。
主要能力:自动同步 React Native bridge、动画与网络请求;使用 waitFor() 显式等待,推荐 toBeVisible() 而非 toExist() 以提升稳定性。测试组织采用 AAA(Arrange、Act、Assert)模式,通过 beforeEach()/afterEach() 隔离,describe() 分组,复杂 UI 使用 Page Object 模式。
配置:使用 .detoxrc.json 定义 testRunner、apps(iOS/Android 的 debug/release 构建与 binaryPath)、devices(模拟器/仿真器)及 configurations;Jest 配置示例包含 globalSetup、globalTeardown、reporter、testEnvironment 等。
用法:元素匹配支持 by.id、by.text、by.label、by.type、by.traits 及组合匹配;操作包括 tap、multiTap、longPress、typeText、replaceText、clearText、scroll、swipe、pinch;断言包括 toBeVisible、toExist、toBeFocused、toHaveText、toHaveValue、toHaveToggleValue、toHaveSliderPosition 等。调试可用 device.takeScreenshot、getAttributes、disableSynchronization 处理 WebView,launchApp 设置权限,以及处理键盘问题。CI/CD 提供 GitHub Actions 的 iOS 与 Android 示例,使用 npx detox build 与 npx detox test。
适用场景:React Native 应用的移动端 E2E 测试、自动化回归与 CI 集成。
限制:资料未提供具体收费、价格、平台支持范围或效果数据;部分示例依赖 iOS/Android 构建环境与模拟器/仿真器配置。