Spectron is an end-to-end testing framework designed specifically for Electron applications. It leverages ChromeDriver and WebdriverIO to provide an API for interacting with Electron apps, allowing developers to simulate user interactions and assert application state. The current stable version is 19.0.0. However, Spectron was officially deprecated on February 1, 2022, and is no longer actively maintained. Its primary differentiator was its tight integration with Electron, allowing control over both the Electron main process and renderer processes through WebdriverIO. Due to its deprecated status, new projects are advised to seek alternative testing solutions for Electron.
npm install spectronVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up Spectron with Mocha to launch an Electron application, perform basic assertions on window visibility and title, and simulate user interaction like clicking a button.
Migrate to alternative Electron testing frameworks such as Playwright or WebdriverIO directly with a custom setup for Electron, or consider using Electron's built-in APIs for testing.
Always consult the 'Version Map' in the Spectron documentation (or README) to ensure your Spectron version is compatible with your Electron version. For example, Electron v17.0.0 requires Spectron v19.0.0.
Refer to the Spectron changelog for specific breaking changes and migration instructions when upgrading from Spectron 1.x.
Consult `webdriverio` and `chromedriver` documentation for troubleshooting, especially regarding versions and capabilities. Ensure Electron's `main.js` and `package.json` are correctly referenced in the `Application` constructor's `args`.
Ensure `path: electronPath` correctly resolves to the Electron executable. If using `require('electron')`, ensure `electron` is installed as a dependency. For packaged apps, specify the absolute path to the main executable.Verify the `args` array in the `Application` constructor correctly points to your main Electron script (e.g., `path.join(__dirname, '..')`). Check your Electron app's `main.js` for any startup errors. Also, ensure Spectron and Electron versions are compatible according to the 'Version Map'.
Ensure `await this.app.start()` completes successfully before attempting to interact with `this.app.browserWindow` or `this.app.client`. Also, check that `this.app` is properly initialized in your `beforeEach` hook.