Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Electron.js Desktop App Development

Lesson 18 of 28 · javascript

Testing Electron Apps – Spectron & Playwright

Duration: 11 mins

Testing Electron Apps – Spectron & Playwright

Spectron (official but now deprecated)

npm install --save-dev spectron mocha
const { Application } = require('spectron');
const assert = require('assert');

describe('App launch', function(){
  this.timeout(10000);
  let app;
  beforeEach(()=>{ app = new Application({ path: require('electron'), args: ['.'] }); return app.start(); });
  afterEach(()=> app && app.stop());

  it('shows a window', async()=>{ const count = await app.client.getWindowCount(); assert.equal(count, 1); });
});

Playwright (modern, cross‑platform)

npm install --save-dev @playwright/test electron
// tests/electron.test.js
const { test, expect } = require('@playwright/test');
const { _electron: electron } = require('playwright');

test('app has title', async () => {
  const app = await electron.launch({ args: ['.'] });
  const window = await app.firstWindow();
  await expect(window).toHaveTitle(/MyApp/);
});

Playwright can also record videos and run headless CI.

Unit testing the main process

Use any Node test runner (Jest, Mocha) because the main process is just a Node script.

// main.test.js
const { app } = require('electron');
test('app is not null', () => { expect(app).toBeDefined(); });
Previous: Debugging – DevTools, Remote Debugging & LoggingNext: Performance Profiling – Chrome DevTools & Electron‑Performance