skip to content
all examples

Testing a SwiftUI macOS app with e2e

A SwiftUI messaging app for macOS with a mock backend, tested through the accessibility tree with locator tests and agent tests.

A messaging app for macOS, built with SwiftUI, tested end to end through the macOS accessibility tree with e2e.

the chat with alex rivera open next to the chat list, with a shared pdf, a reply, and a voice message

How it works

  • App (e2e-macos/App/): the entry point, the window, and the menu commands. ⌘N starts a chat, ⇧⌘N a group, ⌘1 to ⌘4 switch between Chats, Moments, Calls, and Settings, and ⌘, opens Settings.
  • Mock backend (e2e-macos/Backend/): holds the contacts, chats, and messages, and seeds the same data on every launch. There is no real server.
  • State (e2e-macos/Models/, e2e-macos/Store/): the data types, app state, navigation, and settings.
  • Screens (e2e-macos/Views/, e2e-macos/Design/): chats, conversation, chat info, Moments, calls, and settings, with the theme and shared components.

The app has chats and groups with filters, Archived chats, and Saved messages; sending, replying to, forwarding, editing, and deleting messages, with emoji reactions; attachments (photos, camera, documents, location, contacts, and polls); Moments, with stories and streams you can follow; voice and video calls; and search across chats and messages.

Mock backend settings

Contacts reply to your messages, and new messages arrive now and then. Change this in Settings > Mock backend, or with launch arguments:

ArgumentEffect
-mockAutoReplies NOContacts don't reply to your messages
-mockRandomIncoming NONo new messages arrive on their own

The same settings page also sets the simulated network latency and can simulate being offline.

Getting started

You need macOS 26.6 or newer and Xcode 27.

terminal
npm install
npm run build:macos
open build/DerivedData/Build/Products/Debug/e2e-macos.app

You can also open e2e-macos.xcodeproj in Xcode and run the e2e-macos scheme.

Permissions

e2e drives the app through the desktop engine, so the app that starts it (your terminal, your IDE, or your CI agent) needs two permissions in System Settings > Privacy & Security: Accessibility to drive the app, and Screen Recording for screenshots. Check your setup with:

terminal
npx e2e doctor

End-to-end tests

The tests launch the built app, drive it with the real pointer and keyboard, and quit it after each test, so don't touch them while the tests run. chats and calls use locators only, so they need no model. messages and moments are agentic tests: an agent does the step from a plain-language goal, and locator assertions check the outcome.

TestExpects
Shows the seeded chat list on launchWeekend Hiking and Alex Rivera in the chat list
Opens the first chat on launchThe first chat's messages, not "Pick a chat to start messaging"
Finds a message by searching chats"I'll bring sandwiches" in the results, and Alex's chat hidden
Starts and ends a voice call from a chatThe call screen, then "Call ended"
Sends a text message in a chat (agent)"Running ten minutes late" sent by you
Follows a suggested stream (agent)Orbit Weekly followed, with no Follow button left

The agent tests need a Vercel AI Gateway key, AI_GATEWAY_API_KEY. The agent's context in e2e.config.ts tells it what the app calls things, and the config launches the app with -mockRandomIncoming NO, so no unexpected messages arrive in the middle of a test. To build the app and run the tests:

terminal
npm run test:e2e

Desktop support in e2e is experimental.

Scripts

CommandDescription
npm run build:macosBuild the app with xcodebuild
npm run test:e2eBuild the app and run e2e tests

[ get started ]

your verificationlayerstarts withjust one command

npx e2e init