@e2e-dev/mobile

中文文档
0.12.7发布于 2026/11/13Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 48.4万

Mobile engine (iOS and Android) for e2e agentic end-to-end testing, built on agent-device

原始使用文档
文档目录8 节
  1. Install
  2. What the engine declares
  3. Replay cache
  4. The device fixture
  5. Agent tools
  6. Custom tools with a raw driver session
  7. Secrets
  8. Documentation

@e2e-dev/mobile

The mobile engine for e2e, built on agent-device: iOS simulators, Android emulators, and connected phones through the same e2e/engine contract the browser engine implements. A test written against screen, expect, app, and agent runs on a device target unchanged; nothing in e2e core knows this package exists.

Install

Run npx e2e init and choose Mobile (iOS/Android) for a Settings example with optional AI testing. Init defaults to iOS on macOS and Android elsewhere; change the platform in e2e.config.ts when needed. Or add the packages to an existing project:

npm install --save-dev e2e @e2e-dev/mobile

agent-device needs Xcode with an iOS simulator runtime, or the Android SDK with an emulator. A phone needs Developer Mode and runner signing on iOS, or USB debugging authorized on Android (see Physical devices). Run npx e2e doctor to check the setup before a run.

import type { E2EConfig } from 'e2e';
import { mobile } from '@e2e-dev/mobile';
import { mobileTools } from '@e2e-dev/mobile/tools';
import { gateway } from 'ai';

const iphone = mobile({ platform: 'ios' });
const pixel = mobile({ platform: 'android' });

export default {
  targets: [
    { name: 'iphone', engine: iphone, app: { bundleId: 'Settings' } },
    { name: 'pixel', engine: pixel, app: { bundleId: 'com.android.settings' } },
  ],
  workers: 1,
  agents: {
    default: {
      model: gateway('openai/gpt-6-luna-fast'),
      tools: mobileTools(iphone, pixel),
    },
  },
} satisfies E2EConfig;

A test written against agent, app, screen, and device runs on both targets unchanged. Only a check that names a platform label (General on iOS, Network & internet on Android) needs platforms: ['ios'] or platforms: ['android'] on the test.

The app under test is the target's app; the engine only drives it. A device target needs bundleId or appPath:

KeyMeaning
bundleIdBundle id, package, or display name app.open(), app.restart(), and app.clearState() launch fresh; an attempt launches nothing on its own.
appPathAn iOS .app bundle or Android .apk, resolved against the project root. The engine does not install it: the suite calls device.installApp() (with no path, this build) once per device, unless a device provider already installed it. Without bundleId, the installed bundle id or package is the app app.open() launches.
launchArgumentsArguments every fresh launch of the pinned app carries (app.open(), app.restart(), app.clearState()): the process arguments on iOS, am start arguments on Android. The warm-up passes none.
permissionsPermissions the pinned app holds on every fresh launch, { camera: 'grant', location: 'deny', notifications: 'reset' }, set before the app starts and put back after app.clearState() reset them.

app.url is not supported on a device target yet, and mobile({ app }) and the other old app options are INVALID_CONFIG naming their key under app.

mobile() options:

OptionMeaning
platform'ios' or 'android'.
deviceSimulator or emulator name or UDID, or a connected phone's name. A list is a pool: one worker per entry, worker slot n driving the nth. Omitted, every booted device of the platform is the pool, as many as the run has slots.
sessionagent-device session name, before the worker slot: slot n drives its device under <session>-<n>, e2e-<target name>-<n> by default. One run per session at a time.
snapshot'full' (default, includes static text) or 'interactive' (actionable nodes only).
settleMilliseconds the UI must hold still after an agent action before the agent observes again, default 150; false skips the wait. A test's steps do not settle, except device.back(); expect verifies their outcome.
transitionFor a test's steps: milliseconds a control that appeared or moved with the last action gets to finish arriving before it is acted on, default 500. Unmoved controls are acted on immediately only when keyboard visibility is unchanged. Opening or closing the keyboard also uses the remaining budget. Screen swipes in tests wait out the remaining budget before scrolling.
videoTouchesFor recordings the mobile engine makes (not a device provider's own recording), whether the video draws agent-device's touch indicator where a test tapped, default true. false records the plain screen and skips drawing the indicator after the recording stops, which on a hosted daemon can outlast cleanupTimeout.

Every optional mobile() value also accepts undefined, so a config passes device: process.env.E2E_DEVICE straight through, with no conditional spread.

What the engine declares

  • Observation: the accessibility tree, projected onto the role vocabulary (iOS Button becomes button, TextField becomes textbox, Cell becomes listitem; Android android.widget.TextView becomes text, EditText becomes textbox, Switch becomes switch), with rects, a viewport, and pixels on request with every secure field painted over. Element identifiers (ABOUT, android:id/title) are the node's testId, what getByTestId matches.
  • Actions: tap, double tap, long press, fill, clear, check/uncheck (when the tree exposes the checked state, as switches do on both platforms), focus on editable fields, Enter, single-character keys, swipe within a node, drag. selectOption, setInputFiles, scrollIntoView, secondaryTap, modifiers on tap or doubleTap, focus on a control, and other keys fail with UNSUPPORTED_CAPABILITY.
  • Location: every screen query, plus agent-device selectors through device.locator('role=navigation-bar id=General').
  • Viewport swipe, app.back(), app.restart(), app.clearState(), and redacted screenshots under the attempt artifact directory: the bounds of every secure field are painted black before the file is kept, and a screenshot that cannot be redacted is not written. No state capability: a simulator has no portable session snapshot.
  • App kind: a target with app.bundleId or app.appPath is a native-app target, so a portable suite can requires: ['native-app'].

Replay cache

The runner caches agent.act steps by their location anchor, and a device has no address bar. This engine reports one anyway: <bundle id> / <screen title>, with the title read off the navigation bar on iOS and the collapsing toolbar on Android. The app identity is part of the location, so two apps with a "General" screen never share an anchor. A step recorded on com.apple.Preferences / General replays only when that app is on that screen again, and a flow that stays within tap, type, and scroll replays with zero model calls. Declare app.bundleId and call app.open() first, so steps start on the same screen, and prefer the grammar over the open_app tool inside a step: a tool call is a replay gap.

The device fixture

Deterministic device management, recorded as device.<method> steps. Import test from this package to have it typed.

import { test } from '@e2e-dev/mobile';
import { expect } from 'e2e';

test('shows the version in dark mode', async ({ agent, device, screen }) => {
  await device.setAppearance('dark');
  await agent.act('go to General, then About');
  await expect(screen.getByRole('button', /^iOS Version/)).toBeVisible();
  await expect(device.locator('role=navigation-bar id=About')).toBeVisible();
});

Methods: setNetwork, setAirplaneMode, setPermission, setLocation, clearLocation, setAppearance, setOrientation, fold, setBiometrics, enrollBiometrics, installApp, openApp, openLink, closeApp, clearKeychain, foregroundApp, home, back, alert, dismissKeyboard, clipboard, setClipboard, and the locator accessor.

device.unstable_raw is the raw driver session, for what the methods do not cover. Its client calls are not steps: the report and trace leave them out, the cache does not replay them, their arguments reach the driver unredacted, and nothing waits for the screen to settle. Reading it after the worker disposes the session throws INVALID_STATE. It can change in any release (reference).

setNetwork('offline') and setAirplaneMode(true) are Android only. An iOS simulator shares the Mac's network, and simctl can only change its status bar, so on iOS both fail with UNSUPPORTED_CAPABILITY; going back online does nothing there, so a shared cleanup hook passes. On Android, setNetwork('offline') turns off Wi-Fi alone, so the app can stay online over cellular; setAirplaneMode(true) (Android 11 or later) takes it offline.

installApp(appPath, { app, reinstall }) puts a build on the device from a test, for upgrade and fresh-install paths the target's app.appPath cannot express. A plain install replaces the binary and keeps its data; reinstall: true removes the app named by app (default: the pinned app) first. It resolves to the bundle id or package to openApp the build by, else the app passed in; with no reported id and no app, it fails with ENGINE_FAILURE. openApp takes an app id, never a link; openLink opens one, under the navigation rule.

Agent tools

@e2e-dev/mobile/tools exports mobileTools(...engines): open_app, swipe (free-form, in logical pixels), and alert (accept or dismiss a system alert). It takes at least one engine. Pass every device engine the config declares: tool names are fixed, so two packs cannot be merged, and the pack dispatches each call to the engine whose attempt is running. Tools are scoped to the platforms of those engines, so a suite that mixes web and device targets can hand the pack to one agents entry's tools.

Custom tools with a raw driver session

unstable_deviceSession(...engines) from @e2e-dev/mobile/tools gives a custom tool the running attempt's raw driver session, for capabilities e2e does not wrap yet. Its client is bound to the engine's daemon, lease, and session. The client is typed as DeviceSessionClient, exported from @e2e-dev/mobile. This API can change in any release, like device.unstable_raw (reference).

Secrets

type_secret and screen.getByLabel(...).fill(secret) fill declared secrets on a device: a credential's password into a secure field, a secrets entry into any editable input. The model never sees the value, and screenshots are withheld for the rest of the attempt.

Documentation

Full documentation lives at e2e.com/docs.

版本与发布记录

@e2e-dev/mobile 共发布 54 个版本,首次发布于 2026/09/29;过去 12 个月发布了 54 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.12.7latest2026/11/13今天
0.12.7-nightly-20261113123338nightly2026/11/13今天
0.12.7-nightly-202611130943592026/11/13今天
0.12.7-nightly-202611130302072026/11/13今天
0.12.7-nightly-202611120302002026/11/121 天前
0.12.7-nightly-202611100302172026/11/103 天前

其他发布通道:canary → 0.8.0-canary-20260929180659,nightly → 0.12.7-nightly-20261113123338。

关于 @e2e-dev/mobile 的常见问题

@e2e-dev/mobile 是什么?

Mobile engine (iOS and Android) for e2e agentic end-to-end testing, built on agent-device

如何安装 @e2e-dev/mobile?

在项目目录运行 npm install @e2e-dev/mobile,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:e2e(>=0.22.1 <1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@e2e-dev/mobile 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@e2e-dev/mobile 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@e2e-dev/mobile 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.22.3 || >=24.8.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@e2e-dev/mobile 可以商用吗?

@e2e-dev/mobile 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@e2e-dev/mobile 的下载量有多少?

根据 npm 官方下载统计,@e2e-dev/mobile 在 2026/10/13 – 2026/11/11 这 30 天内被下载 483,891 次,日均约 16,130 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@e2e-dev/mobile 还在维护吗?

最新版本 0.12.7 发布于 2026/11/13(今天);至今共发布 54 个版本,其中过去 12 个月发布了 54 个;首次发布于 2026/09/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。