Detox

From G1Joshi/Agent-Skills · View interactive version

Detox is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Detox mobile E2E automation for React Native applications on iOS and Android. Use when running gray-box integration tests, simulating device interactions, or debugging mobile flakiness.

How to use this skill

Skill file

Detox

Detox is designed for React Native. Unlike Appium (Black-box), Detox works "Gray-box" by running _inside_ your app, monitoring the main thread. It _knows_ when the app is busy/idle, eliminating flaky waits.

When to Use

Quick Start

describe("Example", () => {
  beforeAll(async () => {
    await device.launchApp();
  });

  it("should show hello screen after tap", async () => {
    await element(by.id("hello_button")).tap();
    await expect(element(by.text("Hello!!!"))).toBeVisible();
  });
});

Core Concepts

Gray-Box Synchronization Architecture

Detox monitors the app internally (network requests, animations, timers, UI layout passes) and executes actions only when the app is completely idle:

[ Detox Test Runner ] ──(WebSocket)──→ [ Native Detox Agent (Inside App) ]
                                              ├── Monitors React Native Bridge
                                              ├── Tracks Ongoing Network Requests
                                              └── Waits for Zero Pending Animations

Matchers & Actions Hierarchy

Interacts with native elements using accessibility IDs:

// e2e/checkout.test.ts
import { by, element, expect } from "detox";

describe("Checkout Flow", () => {
  beforeAll(async () => {
    await device.launchApp({ newInstance: true });
  });

  it("adds item to cart and proceeds to payment", async () => {
    await element(by.id("item_card_101")).tap();
    await element(by.id("add_to_cart_btn")).tap();

    await expect(element(by.id("cart_badge"))).toHaveText("1");
    await element(by.id("cart_icon")).tap();
    await element(by.id("checkout_button")).tap();

    await expect(element(by.text("Payment Options"))).toBeVisible();
  });
});

Device Control & Deep Linking

Controls simulator state, permissions, and URL schemes:

it("handles incoming deep links", async () => {
  await device.openURL({ url: "myapp://promo/summer2026" });
  await expect(element(by.id("promo_banner"))).toBeVisible();
});

Common Patterns

Synchronized User Flow with Test IDs

Problem: Test flakiness due to timing differences across mobile platforms.

Solution:

Assign testID props in React Native and query using by.id:

describe("Authentication Flow", () => {
  beforeAll(async () => {
    await device.launchApp({ delete: true });
  });

  it("logs in with valid credentials", async () => {
    await element(by.id("email_input")).typeText("user@example.com");
    await element(by.id("password_input")).typeText("secret123");
    await element(by.id("login_button")).tap();
    await expect(element(by.id("welcome_header"))).toBeVisible();
  });
});

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :---------------------------------------------- | :---------------------------------------------------------------- | :---------------------------------------------------------------------------------- |

| DetoxRuntimeError: App synchronization failed | Continuous background loops, animations, or timers blocking sync. | Disable indefinite timers in test mode or use device.disableSynchronization(). |

| Cannot find simulator/emulator | Device name in detox configuration does not exist in local SDK. | Run xcrun simctl list or emulator -list-avds and update .detoxrc.js. |

| Test failed: Element not found | Native view missing testID or collapsed in hierarchy. | Ensure testID is passed to the underlying native component and visible on screen. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.