skip to content
all examples

Testing an Electron app with e2e

A demo Electron app, tested on macOS, Windows, and Linux with locator tests and agent tests.

A Slack clone built with Electron. There is no real server: the backend is mocked in the main process and the UI talks to it over IPC.

Run it

terminal
npm install
npm start

It runs on macOS, Windows, and Linux.

Test it

The end-to-end tests use e2e with the Electron engine. It launches the app, drives its window, and quits it after each test:

terminal
npx e2e run

tests/slack.e2e.ts uses locators only, so it needs no model. The other files are agentic tests: an agent drives each feature from a plain-language goal, and locator assertions check the outcome. They run when AI_GATEWAY_API_KEY is set, and are skipped otherwise.

FileCovers
tests/messages.e2e.tsSending a message to another channel, editing and deleting your own message
tests/threads.e2e.tsReplying in a thread
tests/reactions.e2e.tsReacting with an emoji from the picker
tests/channels.e2e.tsCreating a private channel, and the error for a name that's taken
tests/direct-messages.e2e.tsMessaging Ada, and starting a conversation with a new coworker
tests/search.e2e.tsFinding messages, and opening a result in its channel
tests/mentions.e2e.tsMentioning a coworker, and your mentions in Activity
tests/profile.e2e.tsSetting yourself as away, and switching the theme

The agent's context in e2e.config.ts tells it what the app calls things. A full run with the model costs about $0.03. After a passing run, e2e replays the recorded steps from .e2e/cache/ without calling the model, except the mention step, whose typing it redoes each time.

The config turns off the simulated activity (see below), so every run sees the same screens.

Electron support in e2e is experimental, so @e2e-dev/electron is pinned to an exact version.

On Windows

You need Node.js 22.22.3 or newer. On a clean Windows install, also install the Microsoft Visual C++ Redistributable for your CPU (x64 or ARM64). The electron package needs it to unpack its binary. Without it, npm start and npx e2e run fail with Cannot find native binding.

In PowerShell, if running scripts is disabled, use npm.cmd and npx.cmd instead of npm and npx.

On Linux

You need Node.js 22.22.3 or newer. The nodejs package in Ubuntu 26.04 is older, so install Node.js from nodejs.org instead. Run the app and the tests from a terminal in your desktop session (Wayland or X11), so the window has a display.

On Ubuntu 24.04 and newer, npm start crashes with The SUID sandbox helper binary was found, but is not configured correctly. Ubuntu's AppArmor blocks the user namespaces that Chromium's sandbox needs. Allow them for the Electron binary in this project once, from the project directory, with the sandbox still on:

terminal
sudo tee /etc/apparmor.d/e2e-electron > /dev/null <<EOF
abi <abi/4.0>,
include <tunables/global>

profile e2e-electron $PWD/node_modules/electron/dist/electron flags=(unconfined) {
  userns,
}
EOF
sudo apparmor_parser -r /etc/apparmor.d/e2e-electron

npx e2e run doesn't need this, because the Electron engine starts the app with --no-sandbox on Linux.

What's inside

  • src/main/main.js: creates the window, connects the mock backend to IPC, and saves the theme choice.
  • src/main/mock-backend.js: the in-memory backend. It holds the users, channels and messages, and simulates replies, typing, presence changes and new messages.
  • src/preload.cjs: exposes the backend to the page as window.api.
  • src/renderer/: the UI, written in plain HTML, CSS and JavaScript.
  • src/renderer/assets/avatars/: profile photos for the mock users. They are stock photos from Unsplash, stored locally so the app works offline.

Features

  • Channels (public and private) and direct messages, with unread counts and mention badges
  • Sending, editing (press ↑ in an empty composer) and deleting messages
  • Threads, emoji reactions, and @mention autocomplete
  • Formatting: *bold*, _italic_, ~strike~, `code`, ```blocks```, and links
  • Search (⌘K, or Ctrl+K on Windows and Linux), an Activity panel with your mentions, and conversation details
  • Creating channels and starting new DMs
  • Typing indicators and presence
  • Light and dark themes. The app follows your system setting; switch it from your profile menu (bottom left)

Environment variables

Coworkers reply to your messages, and new messages show up in other channels now and then. To keep runs predictable, for example in tests, turn this off and pin the theme with environment variables:

VariableEffect
SLACK_MOCK_AUTOREPLY=0Coworkers don't reply to your messages
SLACK_MOCK_AMBIENT=0No new messages or presence changes over time
SLACK_MOCK_LATENCY=0No simulated network delay (default: 120 ms)
SLACK_THEME=lightStart in light, dark or system theme, ignoring the saved choice

The app starts with the same seed data each time.

License

The code is under the MIT License. The avatar photos are not covered by it: they are under the Unsplash License.

[ get started ]

your verificationlayerstarts withjust one command

npx e2e init