> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Desktop

> Test a native macOS desktop app with @e2e-dev/desktop, which reads and drives the app through the accessibility tree with the same APIs as web tests.

`@e2e-dev/desktop` runs tests on native desktop apps. It reads and drives
the app through the OS accessibility tree with a native driver that runs in
the test process. Tests use the same `agent`, `screen`, and `expect` APIs as
browser tests.

<Warning>
  **Desktop support is experimental.** The `desktop()` options, the `desktop`
  fixture, and how the engine behaves can change in any release, including a
  patch, until it's stable. Pin `@e2e-dev/desktop` to an exact version in
  `package.json`, with no `^`, and read the
  [release notes](https://github.com/e2e-inc/e2e/releases) before you upgrade.
</Warning>

The engine runs on macOS 13 or later only. A config with a desktop target
still loads on Windows and Linux, and its other targets run there when you
pick them with `--target`. A run that includes the desktop target stops with
`UNSUPPORTED_CAPABILITY` before any test starts.

## Set up

Install the runner and the engine:

<CodeGroup>
```bash npm
npm install --save-dev e2e @e2e-dev/desktop
```

```bash pnpm
pnpm add --save-dev e2e @e2e-dev/desktop
```

```bash bun
bun add --dev e2e @e2e-dev/desktop
```
</CodeGroup>

On macOS, the app that starts e2e needs two permissions in **System Settings
> Privacy & Security**. That app is your terminal, your IDE, or your CI agent.

- **Accessibility**, to read and drive the app.
- **Screen Recording**, for screenshots.

npm installs the driver for your Mac with the engine, as
`@e2e-dev/desktop-darwin-arm64` or `@e2e-dev/desktop-darwin-x64`. You don't
need Rust or Xcode.

Check your setup:

<CodeGroup>
```bash npm
npx e2e doctor
```

```bash pnpm
pnpm exec e2e doctor
```

```bash bun
bunx e2e doctor
```
</CodeGroup>

It checks the driver, both permissions, and the `appPath` build.

In a project with no e2e config yet, `npx e2e init --yes --engine desktop`
writes the config and an example test for you.

## Point at your app

Set the target's `app.appPath` to a built `.app` bundle. Or set
`app.bundleId` to an installed app's bundle id or name, such as
`com.apple.calculator`. With both, the `appPath` build is launched, and its
bundle id must be `bundleId`. `app.launchArguments` go to every launch. An
object entry becomes `-name value`, as on iOS, so
`{ AppleLanguages: ['fr'] }` opens the app in French.

The launched app gets only a minimal environment, so your secrets, model
keys, and CI tokens never leak into it. The reference lists
[the variables it gets](https://e2e.com/docs/reference/desktop#environment) and the launch
argument some apps get with them.

```ts title="e2e.config.ts"

export default {
  targets: [
    {
      name: 'mac',
      engine: desktop(),
      app: { appPath: 'build/MyApp.app' },
    },
  ],
  credentials: {
    ada: { username: 'ada', password: process.env.ADA_PASSWORD ?? '' },
  },
} satisfies E2EConfig;
```

## Write a test

Import `test` from `@e2e-dev/desktop`. By default, `app.open()` leaves the
app in the background. Run with `--headed` for apps that need to come forward
before they show a window. `desktop({ physicalInput: true })` brings the app
forward too, and turns on the physical input described below. When the engine
launched it before, it quits that copy first. A copy you opened yourself is left alone,
and the engine never reads or drives it. An app that runs one copy at a time
hands the launch to a copy that is already running, so `app.open()` fails and
names that copy: quit it first. Every test ends with the app quit, and no
window the app saved at its last quit comes back.

```ts title="tests/sign-in.e2e.ts"

test('signs in', async ({ app, screen }) => {
  const ada = credentials.user('ada');
  await app.open();
  await screen.getByRole('textbox', 'Username').fill(ada.username);
  await screen.getByRole('textbox', 'Password').fill(ada.password);
  await screen.getByRole('combobox', 'Plan').selectOption('Team');
  await screen.getByRole('button', 'Sign in').tap();
  await expect(screen.getByTestId('status')).toContainText('Signed in as ada');
});
```

Roles use the names the web uses: `textbox`, `checkbox`, `combobox`,
`button`. Find static text with `getByText`. macOS names a field with no
label by its placeholder, so find it with `getByRole('textbox', 'Username')`
or `getByLabel('Username')`; `getByPlaceholder` isn't supported. `getByTestId` finds the
control's `AXIdentifier` (`accessibilityIdentifier` in AppKit and SwiftUI).
See [Roles and names](https://e2e.com/docs/reference/desktop#roles-and-names) for how macOS
elements map to roles.

## The desktop fixture

`desktop` is what a test asks of the desktop itself: list and switch windows
with `windows()`, `waitForWindow()`, and `window()`, send keys with
`keyboard.press()` and `keyboard.type()`, and quit the app with `closeApp()`.
The [desktop engine reference](https://e2e.com/docs/reference/desktop#the-desktop-fixture) lists
every member with its parameters, defaults, and errors.

## Work with several windows

`screen` reads the active window. Until a test picks one, that's the app's
focused window, so a dialog that takes focus is read without a step of its
own. `desktop.waitForWindow()` runs the step that opens a window and makes
that window active. It then stays active, whichever window has focus, until it
closes. After that, `screen` reads the focused window again.

```ts
const settings = await desktop.waitForWindow(() =>
  screen.getByRole('button', 'Settings…').tap(),
);
await expect(screen.getByRole('checkbox', 'Launch at login')).toBeVisible();

const main = await desktop.window({ title: 'My App' });
await main.activate();
await settings.close();
```

A window has `title()`, `isActive()`, `isClosed()`, `activate()`, and
`close()`. Each one asks macOS, so `await` them all. `title` takes an exact
string or a `RegExp`. Use `desktop.window()` for a window the app opens by
itself. See
[Windows and the active window](https://e2e.com/docs/reference/desktop#windows-and-the-active-window)
for which window `screen` reads when a test picked none.

## What differs from the web

| Area | On a desktop target |
| --- | --- |
| Input | The app runs in the background. Actions use the macOS Accessibility API, so your mouse and keyboard stay free. Apps that don't open a window in the background, like document-based apps, need `--headed` or `physicalInput: true`. See [Input](https://e2e.com/docs/reference/desktop#input) |
| Physical input | `doubleTap`, `hover`, and coordinate taps require `desktop({ physicalInput: true })`, which brings the app forward and uses the real pointer and keyboard. See [Physical input](https://e2e.com/docs/reference/desktop#physical-input) |
| Keys | `press` and typing reach only the focused control in the app's key window, and system shortcuts like `ControlOrMeta+q` are blocked: use `desktop.closeApp()`. Without `physicalInput`, a `ControlOrMeta` shortcut reaches only the app's menu bar. For an app with no control that takes keyboard focus, like Calculator, use `desktop.keyboard.press()`. See [Keys](https://e2e.com/docs/reference/desktop#keys) |
| Select | `selectOption` matches by option label, not index. For editable combo boxes, use `fill()` instead. See [Select](https://e2e.com/docs/reference/desktop#select) |
| Windows | `screen` reads the [active window](#work-with-several-windows), with its sheets and open menus. Minimized windows and rows scrolled out of their list read as hidden, so `getByRole` skips them. See [Visibility](https://e2e.com/docs/reference/desktop#visibility) |
| Reading | If the screen is locked or the window is too deep or too large to read whole, locators keep retrying until timeout instead of returning false negatives. See [Reading a window](https://e2e.com/docs/reference/desktop#reading-a-window) |
| Menu bar | The app's menu bar isn't readable yet; trigger menu items with a key shortcut (`press`). |
| Web content | Browser windows, Electron apps, and web views aren't supported. Use `@e2e-dev/web` for web apps and [`@e2e-dev/electron`](https://e2e.com/docs/electron) for Electron apps. |
| Workers | Limited to one worker per desktop target. If you run two desktop targets with `physicalInput: true`, set `workers: 1` so they don't fight over the cursor and keyboard. |
| Scrolling | `scrollTo(edge)` isn't supported. Use `scrollUntilVisible` instead. |
| State | `app.clearState()` and `app.back()` aren't supported yet, and neither are a `test.setup` session or `video: 'on'`. |
| Not supported | `getByPlaceholder`, `toBeInViewport`, `toBeEmpty`, `blur`, `longPress`, `dragTo`, `setInputFiles`, tap `modifiers`, and `selectOption({ index })` fail with a message that says so. |
| Secrets | Password fields never expose their value and are painted black in screenshots. A screenshot that can't cover one fails instead of saving. |

`desktop()` takes four options: `snapshot`, `physicalInput`, `settle`, and
`maxDepth`. See [Options](https://e2e.com/docs/reference/desktop#options).

## Next

<CardGroup cols={2}>
  <Card title="Desktop engine reference" icon="book" href="/reference/desktop">
    Every option and `desktop` fixture member, with defaults and errors.
  </Card>
  <Card title="Mobile" icon="mobile" href="/mobile">
    Run the same tests on iOS simulators and Android emulators.
  </Card>
  <Card title="Agent steps" icon="robot" href="/agent-steps">
    Let the agent fill a form or check the screen.
  </Card>
</CardGroup>
