Skip to main content

Electron Service

@wdio/electron-service is a 3rd party package, for more information please see GitHub | npm

@wdio/electron-service Version Downloads (v10+) Downloads (≤ v9)

WebdriverIO service for testing Electron applications

Enables cross-platform E2E testing of Electron apps via the extensive WebdriverIO ecosystem.

Spiritual successor to Spectron (RIP).

v10 highlights — the package is now scoped as @wdio/electron-service. v10 adds class mocking (browser.electron.mock('Tray')), main- and renderer-process console log capture, deeplink testing (browser.electron.triggerDeeplink()), an electronBuilderConfig option for projects with multiple build configs, and a mode: 'browser' option for testing the renderer in plain Chrome against a Vite dev server without an Electron binary. See the v10.0.0 release notes for the full list, or the v9 → v10 migration guide if you're upgrading.

Features

Makes testing Electron applications much easier via:

  • 🚗 Auto-setup of required Chromedriver (for Electron v26 and above)
  • 📦 Automatic path detection of your Electron application
  • 🧩 Access Electron APIs within your tests
  • 🕵️ Mocking of Electron APIs via a Vitest-like API
  • 🔗 Deeplink/protocol handler testing support
  • 📊 Console log capture from main and renderer processes
  • 🖥️ Headless testing support
    • Automatic Xvfb integration for Linux environments (requires WebdriverIO 9.19.1+)

Installation

You will need to install WebdriverIO, instructions can be found here.

Note: WebdriverIO 9.19.1+ is required for automatic Xvfb support via the autoXvfb configuration option. For legacy WDIO versions, you'll need to use external tools like xvfb-maybe or manually set up Xvfb for headless testing on Linux. See the Common Issues section for more details on Xvfb setup.

Quick Start

The recommended way to get up and running quickly is to use the WDIO configuration wizard.

Manual Quick Start

To get started without using the configuration wizard, you will need to install the service and @wdio/cli:

npm install --save-dev @wdio/cli @wdio/electron-service

Or use your package manager of choice - pnpm, yarn, etc.

Next, create your WDIO configuration file. For inspiration, see the self-contained package test apps in this repository or the WDIO configuration reference.

You will need to add electron to your services array and set an Electron capability, e.g.:

wdio.conf.ts

export const config = {
// ...
services: ["electron"],
capabilities: [
{
browserName: "electron",
},
],
// ...
};

Finally, run some tests using your configuration file.

This will spin up an instance of your app in the same way that WDIO handles browsers such as Chrome or Firefox. The service works with WDIO (parallel) multiremote if you need to run additional instances simultaneously, e.g. multiple instances of your app or different combinations of your app and a Web browser.

If you use Electron Forge or Electron Builder to package your app then the service will automatically attempt to find the path to your bundled Electron application. You can provide a custom path to the binary via custom service capabilities, e.g.:

wdio.conf.ts

export const config = {
// ...
capabilities: [
{
browserName: "electron",
"wdio:electronServiceOptions": {
appBinaryPath: "./path/to/built/electron/app.exe",
appArgs: ["foo", "bar=baz"],
},
},
],
// ...
};

See the configuration doc for how to find your appBinaryPath value for the different operating systems supported by Electron.

Alternatively, you can point the service at an unpackaged app by providing the path to the main.js script. Electron will need to be installed in your node_modules. It is recommended to bundle unpackaged apps using a bundler such as Rollup, Parcel, Webpack, etc.

wdio.conf.ts

export const config = {
// ...
capabilities: [
{
browserName: "electron",
"wdio:electronServiceOptions": {
appEntryPoint: "./path/to/bundled/electron/main.bundle.js",
appArgs: ["foo", "bar=baz"],
},
},
],
// ...
};

Chromedriver Configuration

If your app uses a version of Electron which is lower than v26 then you will need to manually configure Chromedriver.

This is because WDIO uses Chrome for Testing to download Chromedriver, which only provides Chromedriver versions of v115 or newer.

Documentation

Getting Started

Reference

Operations

  • Browser Mode — test the renderer in Chrome against a Vite dev server, no Electron binary required
  • Deeplink Testing — protocol handler tests across platforms
  • Standalone Mode — using the service without the WDIO test runner
  • Visual Testing — visual regression with @wdio/visual-service
  • Video Recording — record video of test runs with wdio-video-reporter
  • Debugging — log capture, debug namespaces, troubleshooting
  • Common Issues — known issues and workarounds

Migration & Release Notes

Contributing

Development

Read the development doc if you are interested in contributing.

Example Integrations

Check out our Electron boilerplate project that showcases how to integrate WebdriverIO in an example application. You can also have a look at the package test apps, E2E test apps, and E2E test suites in this repository.

Support

If you are having issues running WDIO with the service you should check the documented Common Issues in the first instance, then open a discussion in the main WDIO forum.

The Electron service discussion forum is much less active than the WDIO one, but if the issue you are experiencing is specific to Electron or using the service then you can open a discussion here.

Welcome! How can I help?

WebdriverIO AI Copilot