Do I have to use Spectron to test Electron?

In terms of end to end testing I would say that Spectron is the way to go. It can be pretty hard to get up and running, but Spectron is built upon WebdriverIO and there you'll find a lot of documentation.

To get up and running I would propose the following.

npm install spectron mocha --save-dev

my-first-test-case.e2e.js

const electron = require('electron');

describe('my first test case', function () {

  beforeEach(() => {
    this.app = new Application({
      path: electron,
      args: ['.'],
    });

    return this.app.start();
  });

  afterEach(() => {
    if (this.app && this.app.isRunning()) {
      return this.app.stop();
    }
  });

  it('creates a new tab when account is added', function () {
    const accountName = 'awesomeMail';

    return this.app.client.waitUntilWindowLoaded()
      .waitForVisible('h1')
      .getText('h1')
      .then(text => expect(text).toEqual('Welcome'));
  });
});

And then you run

mocha my-first-test-case.e2e.js

Or if you dont have mocha installed globally

node_modules/.bin/mocha my-first-test-case.e2e.js


I tried to test electron app with java for a while but I just came back to Spectron again because of my applications structure. If you want to test your electron app with other options(java,phyton and selenium) you can set browser options and capabilities for it as you can see in the below.

Example of Java code:

 ChromeOptions options = new ChromeOptions();
    options.setBinary(binaryPath);
    options.addArguments("--app=" + argPath);
    options.setCapability("chromeOptions", options);
    driver = new ChromeDriver(options);