detox-skill: Generate Detox Gray-Box E2E Tests for React Native

Preface

End-to-end testing React Native apps on real devices and simulators often requires juggling Jest test structure, Detox’s element(by.id()) selectors, the .detoxrc.js build configuration, and the separate build commands for iOS and Android. Hand-written boilerplate is prone to missing Detox’s synchronization mechanisms or misusing waitFor polling. Below is the detox-skill maintained by TestMu AI: whenever Detox, RN E2E, or device.launchApp is mentioned in a conversation, the Agent follows the patterns in this skill to generate JavaScript/TypeScript tests and configurations. It targets local simulators/emulators, and can also be wired up to TestMu AI cloud execution per the documentation.

What This Is

detox-skill is an Agent Skill (in SKILL.md format, MIT license, metadata version 1.0) under the LambdaTest agent-skills repository. Its purpose: generate Detox gray-box E2E tests for React Native apps. In the RN community, Detox is a common native-driver E2E solution with automatic synchronization, reducing the need for hand-written waits.

The maintainer is listed in the metadata as TestMu AI (part of the LambdaTest ecosystem). The trigger scenarios described in the skill include keywords such as Detox, React Native E2E, React Native test, element(by.id), device.launchApp, and so on.

Core Features

The capabilities explicitly stated in the materials can be grouped into the following categories (all from the official skill content, not extrapolated).

Test Structure & Lifecycle

  • Organize test cases with describe / it; call device.launchApp() in beforeAll and device.reloadReactNative() in beforeEach to avoid repeating a cold start for every test case.
  • Example flows such as login: locate inputs and buttons by testID, then use typeText and tap, followed by assertions like expect(...).toBeVisible() / toHaveText.

Element Location (Matchers)

  • Prefer element(by.id('...')) (mapped to a component’s testID).
  • Also supports by.text, by.label, by.type, by.traits; combining with withDescendant / withAncestor; and atIndex(n) for multiple matches.

Interactions & Assertions

  • Actions: tap, longPress, multiTap, typeText, replaceText, clearText, scroll, scrollTo, swipe, tapReturnKey, etc.
  • Expectations: toBeVisible, not.toBeVisible, toExist, toHaveText, toHaveToggleValue, toHaveValue.

Device Controls

  • launchApp({ newInstance: true }), reloadReactNative, sendToHome, terminateApp, installApp, shake, setLocation, setURLBlacklist, etc.

Anti-pattern Comparison

The skill uses a table to emphasize: do not sprinkle waitFor().withTimeout() everywhere—trust Detox’s automatic synchronization; components should add testID; avoid calling launchApp() in every test; do not use manual delays.

Project Configuration

  • Provides a complete .detoxrc.js example: testRunner pointing to e2e/jest.config.js; apps with ios.debug / android.debug binaryPath and build commands; devices (such as iPhone 16, Pixel_7_API_34 AVD); and configurations mappings.
  • On the React Native side, controls should set testID (the documentation provides TextInput, Button, Text examples).

Local & Cloud

  • Local: detox build / detox test with configurations like ios.sim.debug, android.emu.debug.
  • Cloud: Detox generates native test runners (Android Espresso, iOS XCUITest); the documentation provides steps to upload APK/IPA and call the Espresso / XCUITest build endpoints on mobile-api.lambdatest.com via TestMu AI (requires LT_USERNAME, LT_ACCESS_KEY).

Advanced

  • Advanced patterns, debugging, CI/CD, etc., point to the reference/playbook.md bundled inside the skill package (this file must be obtained from the repository; this article does not expand on content that was not captured).

Installation & Enablement

Detox Project Side (In-skill Setup)

Install Detox and Jest in an existing React Native project and initialize the directory structure:

npm install detox --save-dev
npm install jest jest-circus --save-dev
detox init

Then adjust the project paths and scheme according to the skill’s .detoxrc.js and component testID examples.

Agent Skill Side

The official entry point is the GitHub directory: detox-skill. The skill uses a generic SKILL.md description (including front matter such as name, description, languages, category: mobile-testing). Integrate the skill definition from this project according to your Agent product’s skill-loading mechanism; the exact menu paths for each editor/CLI should follow their respective documentation. This material does not separately list differences between Cursor and Codex CLI, and no speculative steps are provided here.

Typical Usage

1) Generate a Basic Login Flow Test

Guided by the skill, the Agent should produce a test with a structure similar to the following: launch the app, reload RN before each test case, fill the form via testID, and assert the dashboard or error messages.

describe('Login', () => {
  beforeAll(async () => {
    await device.launchApp();
  });

  beforeEach(async () => {
    await device.reloadReactNative();
  });

  it('should login with valid credentials', async () => {
    await element(by.id('emailInput')).typeText('user@test.com');
    await element(by.id('passwordInput')).typeText('password123');
    await element(by.id('loginButton')).tap();
    await expect(element(by.id('dashboardTitle'))).toBeVisible();
    await expect(element(by.text('Welcome'))).toBeVisible();
  });
});

2) Run Locally on iOS / Android

Build first, then test. Configuration names must match .detoxrc.js:

detox build --configuration ios.sim.debug
detox test --configuration ios.sim.debug
detox build --configuration android.emu.debug
detox test --configuration android.emu.debug

To run only a single file:

detox test --configuration ios.sim.debug e2e/login.test.js

Recording and screenshots: detox test --record-videos all; within a test, await device.takeScreenshot('login-page').

3) Android Cloud-side Espresso (Excerpt)

After building locally, upload the app and the androidTest APK, then trigger a build via POST (device names and authentication are based on your TestMu AI account):

detox build --configuration android.emu.debug

Upload and trigger endpoints are shown in the curl examples in the skill body (upload via manual-api.lambdatest.com, and build via mobile-api.lambdatest.com/framework/v1/espresso/build).

Use Cases & Caveats

Who it’s for

  • Teams maintaining React Native apps who already use or plan to adopt Detox; developers who need to quickly produce community-standard E2E test cases, matcher/action snippets, and a .detoxrc.js skeleton within an Agent conversation.
  • Scenarios that require local verification on simulators/emulators, or pushing the same Detox artifacts to TestMu AI real-device cloud per the official documentation.

Limitations & Notes

  • The skill targets JavaScript / TypeScript and the Detox ecosystem; it is not a generic mobile skill for Appium or Maestro. Mobile-testing skills are relatively scarce in the ecosystem, and this skill is bound to Detox and RN.
  • Cloud execution depends on a LambdaTest/TestMu AI account and correct artifact paths; the example device model strings must match the currently available list on the platform, as per the official API documentation.
  • binaryPath, xcodebuild, and gradlew commands must be adjusted according to your app name and directory layout; MyApp in the skill examples is only a template.
  • The anti-patterns table makes it clear: stability depends on testID and Detox synchronization, not on stacking timeouts and sleeps.

Closing

detox-skill consolidates Detox’s test case structure, selectors, device APIs, configuration, and local/cloud execution essentials into a single Agent Skill, suitable for systematically adding E2E coverage in an RN project. Official link: https://github.com/LambdaTest/agent-skills/tree/main/detox-skill.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye