diff --git a/README.md b/README.md index 79df338c10..4cb5810628 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/docs/core.mdx b/docs/core.mdx index 5bbb805d95..d4f8d7b884 100644 --- a/docs/core.mdx +++ b/docs/core.mdx @@ -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 @@ -36,8 +36,9 @@ bun add @e2e-dev/core @e2e-dev/web 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+. Always import engines from their `/engine` subpath (like @@ -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()))); +``` + + +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. + + +`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 diff --git a/docs/examples/core/desktop.ts b/docs/examples/core/desktop.ts new file mode 100644 index 0000000000..fe677a81c6 --- /dev/null +++ b/docs/examples/core/desktop.ts @@ -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()))); diff --git a/docs/reference/core.mdx b/docs/reference/core.mdx index 6654506e8f..980b25a291 100644 --- a/docs/reference/core.mdx +++ b/docs/reference/core.mdx @@ -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" @@ -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. @@ -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. | | `WORKER_PROTOCOL` | Another host owns this engine instance. Call the factory again: `launch(web())`. | ##### `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). | @@ -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()` | | [`saveState`](#savestate) | `Promise` | | [`setDefaultTimeout`](#setdefaulttimeout) | `void` | | `close` | `Promise` | diff --git a/packages/core/README.md b/packages/core/README.md index cb5c9c1954..3464b03a22 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -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 diff --git a/scripts/check-docs-examples.ts b/scripts/check-docs-examples.ts index 7ed0f83151..3794fdf342 100644 --- a/scripts/check-docs-examples.ts +++ b/scripts/check-docs-examples.ts @@ -31,6 +31,7 @@ const EXAMPLES: Record = { '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',