Set up spectron

Hey I am trying to set up spectron but it seems I am doing something wrong. It would be greate if someone could point me into the correct direction.

here is my code:

const Application = require('spectron').Application;
const electronPath = require('electron'); // Require Electron from the binaries included in node_modules.
const path = require('path');
const assert = require('assert');

const app = new Application({
  path: electronPath,
  args: [path.join(__dirname, '..')],

describe('Testing', function () {
  beforeEach(() => {
    console.log(app); // this is executed
    return app.start(); // troubling line
  afterEach(() => {
    if (app && app.isRunning()) {
      return app.stop();
  it('shows an initial window', function () {
    console.log('count'); // this is not executed
    // const count = app.client.getWindowCount();
    // return assert.equal(count, 1);

Here is my error message:

Application {
  host: '',
  port: 9515,
  quitTimeout: 1000,
  startTimeout: 5000,
  waitTimeout: 5000,
  connectionRetryCount: 10,
  connectionRetryTimeout: 30000,
  nodePath: 'C:\\Program Files\\nodejs\\node.exe',
  path: 'C:\\Users\\vabis\\Desktop\\Playground\\projects\\app\\node_modules\\electron\\dist\\electron.exe',
  args: [ 'C:\\Users\\vabis\\Desktop\\Playground\\projects\\app' ],
  chromeDriverArgs: [],
  env: {},
  workingDirectory: 'C:\\Users\\vabis\\Desktop\\Playground\\projects\\app',
  debuggerAddress: undefined,
  chromeDriverLogPath: undefined,
  webdriverLogPath: undefined,
  webdriverOptions: {},

  0 passing (8s)
  1 failing

  1) Testing
       "before each" hook for "shows an initial window":
     javascript error: javascript error: Cannot convert undefined or null to object
  (Session info: chrome=85.0.4183.121)

My advice: don’t use spectron. I had lots of bugs in multiple projects, it uses “proxy” so sometimes the methods you expect don’t exist yet, and other strange issues…

It’s better to ditch out, use Webdriver manually, or use other language…

@mauricioszabo Thank you for taking the tie to reply. You are actually one of a few.

I could get rid of the above error when I added:

webPreferences: {
enableRemoteModule: isDev, // Need that Spectron will work

However, since I am using react, it seems that it is not rendered to the screen. I thought I could just use this out of the box. I want to use Spectron because it seems that I can set up with Travis. But I am open for other ideas. I actually already thought about of trying out to use selenium directly to write tests. Never used Webdriver.

How would you approach that? Would you simply build your app locally and then run a webdriver program that will test ou every feature? I am more than grateful for any guidance on this topic since I find so little online, and what I find seems outdated.

For later readers I am using Electron 11.21.1 and Spectron 13.0.0

I also tried to get help on Reddit. But no success there, so far.

I have looked at various ways of testing and on first read the Spectron approach seems overly complicated.

My approach is to use external scripts to “drive” the UI and test the outcome.
The choice of automation tool depends on platform but you appear to be in Windows. There is autoit for Windows.

I am in Ubuntu 20.04 and I can use a neat little tool Actiona (although dating back to Flash / Actionscript2) but it is quite useful. Most of the coding is in Actionscript2 but there is a GUI for widgets.

The only cross platform testing environment in my searching around is SikuliX (note the X since this is mark 2) which runs in Java and can use python scripting.

There is also an Atom package - trueautomation from - but I have not yet figured out how to apply it.

Webdriver is just a selenium driver so no worries. I’m currently using Selenium to scrap a electron app and also to test my Atom plug-in (I’m using the Clojure binding to Selenium).

This is the Electron app I’m currently scrapping: repl-tooling/integration.clj at master · mauricioszabo/repl-tooling · GitHub