SuperAPI AI 工具集

detox-skill

测试与质量

查看项目

更新于 10-15 16:21

技能介绍

Detox Automation Skill 是一个面向 React Native 应用、使用 JavaScript 编写 Detox 端到端测试的技能,定位为资深 React Native QA 工程师。它基于 Detox 这一灰盒测试框架,具备自动同步能力。

主要能力与内容模式:

一、基础测试模式 技能提供了 describe/it 结构的登录测试示例,包含 beforeAll 中的 device.launchApp()、beforeEach 中的 device.reloadReactNative(),以及通过 element(by.id(...)) 定位元素、typeText、tap 操作,并用 expect(...).toBeVisible() 进行断言的写法。

二、元素匹配器(Finding Elements) 支持 element(by.id('uniqueId'))(推荐,对应 testID prop)、element(by.text('Login'))(文本内容)、element(by.label('Submit'))(无障碍标签)、element(by.type('RCTTextInput'))(原生类型)、element(by.traits(['button']))(iOS traits)。还支持组合匹配,如 withDescendant、withAncestor,以及多匹配时使用 atIndex(0)。

三、动作(Actions) 包括 tap、longPress、multiTap、typeText、replaceText、clearText、scroll、scrollTo、swipe、tapReturnKey 等。

四、断言(Expectations) toBeVisible、not.toBeVisible、toExist、toHaveText、toHaveToggleValue、toHaveValue。

五、设备控制(Device Control) launchApp(可带 newInstance)、reloadReactNative、sendToHome、terminateApp、installApp、shake、setLocation、setURLBlacklist。

六、抗模式(Anti-Patterns) 技能列出了不良做法与良好做法对照,例如:不要在到处使用 waitFor().withTimeout(),而应信任 Detox 自动同步;组件应添加 testID prop 以获得稳定选择器;用 device.reloadReactNative() 代替每个测试都调用 device.launchApp();避免手动延迟,改用 Detox 同步机制。

七、.detoxrc.js 配置 提供配置示例,包含 testRunner、apps(ios.debug 与 android.debug,含 binaryPath、build 命令、reversePorts)、devices(simulator 与 emulator)、configurations(ios.sim.debug 与 android.emu.debug)。

八、TestMu AI 云端执行 Detox 会生成原生测试运行器(Android 用 Espresso,iOS 用 XCUITest)。技能给出云端运行步骤:上传构建产物并触发框架构建。 Android(Espresso)流程包括:detox build 构建 app 与测试 APK;用 curl 上传 app APK 与 test APK 到 https://manual-api.lambdatest.com/app/upload/realDevice;再向 https://mobile-api.lambdatest.com/framework/v1/espresso/build 触发构建,请求体含 app、testSuite、device、build、deviceLog、video 等字段。 iOS(XCUITest)流程类似:detox build、创建 .ipa 并上传、上传测试运行器 .ipa,再向 https://mobile-api.lambdatest.com/framework/v1/xcui/build 触发构建,请求体含 app、testSuite、device、build、devicelog、video 等字段。

九、快速参考与安装 命令包括 detox build / detox test(按配置区分 iOS 与 Android)、指定测试文件、--record-videos all 录制视频、device.takeScreenshot 截图。安装命令为 npm install detox --save-dev、npm install jest jest-circus --save-dev、detox init。同时提供 React Native 组件添加 testID 的示例(TextInput、Button、Text)。

十、深入模式 技能提示,更多高级模式、调试指南、CI/CD 集成与最佳实践,参见 reference/playbook.md。

适用场景:为 React Native 应用编写与运行 Detox E2E 测试,可在本地模拟器/仿真器执行,也可上传构建产物到 TestMu AI 云端执行。

限制:本资料未提供该技能的收费、价格、具体性能指标或效果数据,这些信息暂未提供。