Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ every tool.
| Package | What it does |
| --- | --- |
| [`e2e`](https://www.npmjs.com/package/e2e) | The SDK, runner, and CLI. |
| [`@e2e-dev/core`](https://e2e.com/docs/core) | Drives a browser or a device from your own program, with an optional agent and no test runner. `e2e` is built on it. |
| [`@e2e-dev/core`](https://e2e.com/docs/core) | Drives a browser, a device, or a Mac app from your own program, with an optional agent and no test runner. `e2e` is built on it. |
| [`@e2e-dev/web`](https://www.npmjs.com/package/@e2e-dev/web) | Browser engine: Chromium, Firefox, and WebKit through Playwright. |
| [`@e2e-dev/mobile`](https://www.npmjs.com/package/@e2e-dev/mobile) | iOS and Android engine: simulators and emulators through agent-device. |
| [`@e2e-dev/desktop`](https://www.npmjs.com/package/@e2e-dev/desktop) | Desktop engine, a prototype: native apps on macOS through its own Rust accessibility driver. |
Expand Down
46 changes: 40 additions & 6 deletions docs/core.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: Browser and device automation
sidebarTitle: Automation scripts
description: "Automate a browser or an iOS or Android app from your own script with @e2e-dev/core, using the e2e engines, screen, and an optional AI agent, with no test runner."
description: "Automate a browser, an iOS or Android app, or a Mac app from your own script with @e2e-dev/core, using the e2e engines, screen, and an optional AI agent, with no test runner."
---

`@e2e-dev/core` drives a browser or an iOS or Android app from plain code. It
uses the e2e engines, `screen`, and the agent, without the test runner: there
is no config file, no report, and no `expect`.
`@e2e-dev/core` drives a browser, an iOS or Android app, or a Mac app from
plain code. It uses the e2e engines, `screen`, and the agent, without the
test runner: there is no config file, no report, and no `expect`.

## When to use it

Expand Down Expand Up @@ -36,8 +36,9 @@ bun add @e2e-dev/core @e2e-dev/web
</CodeGroup>

Install `@e2e-dev/mobile` instead of (or alongside) `@e2e-dev/web` to drive
mobile devices. `@e2e-dev/core` doesn't need the `e2e` test runner installed,
and runs on Node.js 22.22.3+ or 24.8+.
mobile devices, or `@e2e-dev/desktop` to drive Mac apps. `@e2e-dev/core`
doesn't need the `e2e` test runner installed, and runs on Node.js 22.22.3+
or 24.8+.

<Note>
Always import engines from their `/engine` subpath (like
Expand Down Expand Up @@ -166,6 +167,39 @@ The iOS simulator can stop a custom-scheme link at an "Open in ...?" prompt.
Tap its `Open` button when it shows:
`session.screen.getByRole('button', 'Open')`.

## Drive a desktop app

Pass `desktop()` and a Mac app: `appPath` for a built `.app` bundle, or
`bundleId` for an installed app. The session holds a `desktop` fixture
beside `screen` and `app`.

```ts title="sign-in.ts"
import { launch } from '@e2e-dev/core';
import { desktop } from '@e2e-dev/desktop/engine';

await using myApp = await launch(desktop(), { app: { appPath: 'build/MyApp.app' } });
await using session = await myApp.newSession();
await session.app.open();
await session.screen.getByRole('textbox', 'Username').fill('ada');
await session.screen.getByRole('button', 'Sign in').tap();
const windows = await session.desktop.windows();
console.log(await Promise.all(windows.map((window) => window.title())));
```

<Note>
The desktop engine is a prototype that runs on macOS 13 or later only. The
program that starts your script needs the Accessibility and Screen Recording
permissions: see [Desktop](/desktop#set-up). Core doesn't need the `e2e`
package; only the `e2e doctor` check on that page uses it.
Comment on lines +190 to +193

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 · Non-blocking · The Note asks for more than a core script needs

Optional. This does not block the merge.

  • The Note says that the program needs both the Accessibility and the Screen Recording permissions. init refuses to start only when Accessibility is missing (packages/desktop/src/surface.ts:280). Filling fields, tapping, and reading windows work without Screen Recording, which is for screenshots. docs/desktop.mdx:40-41 says "Screen Recording, for screenshots", and this Note does not keep that qualifier.
  • The e2e doctor check on the linked page loads a runner config. In a core project without e2e.config.*, it stops with CONFIG_NOT_FOUND before it checks the desktop permissions (run on the base and on this head).

</Note>

`app.open()` launches the app in the background, unless you pass
`headed: true` to `launch`. An app that opens no window in the background,
like a document-based app, needs `headed: true` or
`desktop({ physicalInput: true })`.
[The desktop fixture](/desktop#the-desktop-fixture) covers windows and
keyboard input.

## Keep a signed-in state

`session.saveState()` captures a browser session's cookies and storage in
Expand Down
10 changes: 10 additions & 0 deletions docs/examples/core/desktop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { launch } from '@e2e-dev/core';
import { desktop } from '@e2e-dev/desktop/engine';

await using myApp = await launch(desktop(), { app: { appPath: 'build/MyApp.app' } });
await using session = await myApp.newSession();
await session.app.open();
await session.screen.getByRole('textbox', 'Username').fill('ada');
await session.screen.getByRole('button', 'Sign in').tap();
const windows = await session.desktop.windows();
console.log(await Promise.all(windows.map((window) => window.title())));
26 changes: 14 additions & 12 deletions docs/reference/core.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: "@e2e-dev/core"
description: "API reference for @e2e-dev/core, with launch, hosts, sessions, saved state, and createAgent, for a program that drives a browser or a device without the test runner."
description: "API reference for @e2e-dev/core, with launch, hosts, sessions, saved state, and createAgent, for a program that drives a browser, a device, or a Mac app without the test runner."
---

`@e2e-dev/core` is the API of a program that drives a browser or a device
with no test runner around it. `launch` returns a host, a host opens
sessions, and `createAgent` puts an agent over a session. The
`@e2e-dev/core` is the API of a program that drives a browser, a device,
or a Mac app with no test runner around it. `launch` returns a host, a host
opens sessions, and `createAgent` puts an agent over a session. The
[guide](/core) shows each of them in use.

```ts title="prices.ts"
Expand Down Expand Up @@ -68,7 +68,8 @@ const shop = await launch(web(), {

- `secrets`: values by name, 6 characters or more each. See
[Pass secrets](/core#pass-secrets).
- `headed`: shows the browser window. A device ignores it.
- `headed`: shows the browser window, or brings a desktop app to the front
when it opens. A device ignores it.
- `signal`: cancels the launch, and every session and operation on the host.
- `handleSignals`: closes the host on SIGINT, SIGTERM, and SIGHUP, then lets
the signal end the program, unless the program listens for it itself.
Expand All @@ -82,24 +83,24 @@ const shop = await launch(web(), {
| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | The first argument is not an engine, or an option or `app` key is unknown. |
| `INVALID_CONFIG` | The engine refuses the app: `web()` without `app.url`, `mobile()` without `app.bundleId` or `app.appPath`. |
| `INVALID_CONFIG` | The engine refuses the app: `web()` without `app.url`, `mobile()` or `desktop()` without `app.bundleId` or `app.appPath`, `desktop()` with `app.url`, `app.permissions`, or an `app.appPath` that isn't a `.app` bundle. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 · Non-blocking · INVALID_CONFIG covers only an appPath without the .app suffix

Optional. This does not block the merge.

This row says that INVALID_CONFIG is thrown for "an app.appPath that isn't a .app bundle". validateApp checks only the name suffix (packages/desktop/src/engine.ts:109). A path that ends in .app but has no Contents/Info.plist, for example an incomplete build, passes that check. Then init throws ENGINE_FAILURE (packages/desktop/src/surface.ts:300).

Run on the base and on this head: appPath: 'build/MyApp.apk' gives INVALID_CONFIG, and an empty build/Empty.app directory gives ENGINE_FAILURE. A program that handles the documented code does not catch the second case.

| `WORKER_PROTOCOL` | Another host owns this engine instance. Call the factory again: `launch(web())`. |

<a id="app" />

##### `app`

What `app.open()` opens on a browser, or launches on a device.
What `app.open()` opens on a browser, or launches on a device or a Mac.

| Field | For | Meaning |
| --- | --- | --- |
| `url` | `web()` | The app's URL. `app.open(path)` resolves against it. |
| `bundleId` | `mobile()` | The installed app to launch. |
| `appPath` | `mobile()` | The app build the program runs against, a `.app` or an `.apk`. See [config](/reference/config#apppath). |
| `bundleId` | `mobile()`, `desktop()` | The installed app to launch. |
| `appPath` | `mobile()`, `desktop()` | The app build the program runs against, a `.app` or an `.apk` (`desktop()` takes a `.app` only). See [config](/reference/config#apppath). |
| `linkBase` | `mobile()` | What `app.open(path)` joins the path to and opens as a link. See [config](/reference/config#linkbase). |
| `identity` | both | The app's name for saved states and recordings. Default: for an HTTP(S) `url`, its origin and base path; for a `file:` `url`, the file's URL; with no `url`, `bundleId`, else `appPath`. See [config](/reference/config#identity). |
| `launchArguments` | `mobile()` | Arguments the app launches with, a list or an object. See [config](/reference/config#launcharguments). |
| `permissions` | both | Permissions to grant or deny, or `'all'` to grant every one the engine can. See [config](/reference/config#permissions). |
| `identity` | all | The app's name for saved states and recordings. Default: for an HTTP(S) `url`, its origin and base path; for a `file:` `url`, the file's URL; with no `url`, `bundleId`, else `appPath`. See [config](/reference/config#identity). |
| `launchArguments` | `mobile()`, `desktop()` | Arguments the app launches with, a list or an object. See [config](/reference/config#launcharguments). |
| `permissions` | `web()`, `mobile()` | Permissions to grant or deny, or `'all'` to grant every one the engine can. See [config](/reference/config#permissions). |

<a id="timeout" />

Expand Down Expand Up @@ -170,6 +171,7 @@ is also disposable: `await using` closes it. A cleanup that fails throws an
| `platform` | `string` |
| `browser` | [`Browser`](/reference/web), with `web()` |
| `device` | [`Device`](/reference/mobile), with `mobile()` |
| `desktop` | [`Desktop`](/reference/desktop), with `desktop()` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 · Non-blocking · Other text on these pages still describes only web and mobile

Optional. This does not block the merge.

This row adds desktop() as a core target. Some text that is not in the diff still names only a browser and a device:

  • packages/core/README.md:98: the app option reads "bundleId or appPath for mobile()". packages/core/README.md:100: headed reads "Show the browser window". This README goes to npm, and its first paragraph now says "or a Mac app".
  • docs/reference/core.mdx:128: the platform values are web, ios, android, or a custom engine's label. desktop() is a first-party engine with platform macos (packages/desktop/src/engine.ts:44).
  • docs/reference/core.mdx:132: newSession opens "one isolated browser context, or the app on the device".
  • docs/core.mdx:207: saveState() is "Not supported on mobile devices." A desktop() session also throws: UNSUPPORTED_CAPABILITY engine desktop has no state capability, so a session on it cannot be saved (run on a Mac at this head).

| [`saveState`](#savestate) | `Promise<SessionState>` |
| [`setDefaultTimeout`](#setdefaulttimeout) | `void` |
| `close` | `Promise<void>` |
Expand Down
8 changes: 4 additions & 4 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# @e2e-dev/core

Drive a browser or an iOS or Android app from code. `@e2e-dev/core` is the
engines, `screen`, and agent of [e2e](https://github.com/e2e-inc/e2e) without
the test runner: no config file, no report, no `expect`. The test runner,
`e2e`, is built on it.
Drive a browser, an iOS or Android app, or a Mac app from code.
`@e2e-dev/core` is the engines, `screen`, and agent of
[e2e](https://github.com/e2e-inc/e2e) without the test runner: no config
file, no report, no `expect`. The test runner, `e2e`, is built on it.

## When to use it

Expand Down
1 change: 1 addition & 0 deletions scripts/check-docs-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const EXAMPLES: Record<string, string> = {
'docs/examples/core/prices.ts': 'docs/core.mdx',
'docs/examples/core/checkout.ts': 'docs/core.mdx',
'docs/examples/core/chat.e2e.ts': 'docs/core.mdx',
'docs/examples/core/desktop.ts': 'docs/core.mdx',
'docs/examples/runner/explore.ts': 'docs/reference/runner.mdx',
'docs/examples/limrun/e2e.config.ts': 'docs/integrations/limrun.mdx',
'docs/examples/limrun/greeting.e2e.ts': 'docs/integrations/limrun.mdx',
Expand Down
Loading