Spectron

19.0.0 · deprecated · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { Application } from 'spectron'
import assert from 'assert'
import electronPath from 'electron' // Require Electron from the binaries included in node_modules.
import path from 'path'

describe('Application launch', function () {
  this.timeout(10000)

  beforeEach(async function () {
    this.app = new Application({
      path: electronPath,
      args: [path.join(__dirname, '..')]
    })
    await this.app.start()
  })

  afterEach(async function () {
    if (this.app && this.app.isRunning()) {
      await this.app.stop()
    }
  })

  it('shows an initial window', async function () {
    // Example assertion: check if the main window is visible
    const isVisible = await this.app.browserWindow.isVisible()
    assert.strictEqual(isVisible, true, 'Initial window should be visible')

    // Example assertion: check window title
    const title = await this.app.client.getTitle()
    assert.strictEqual(title, 'Your Electron App Title', 'Window title should match')
  })

  it('should have a button and click it', async function() {
    const button = await this.app.client.$('#my-button')
    await button.click()
    const text = await this.app.client.$('#status-text').getText()
    assert.strictEqual(text, 'Button clicked!', 'Status text should update after click')
  })
})

view raw JSON →