8

Recently I found some difficulty to plan automation testing for our application using Electron. I've tried to use Spectron, which looks like the official framework to test Electron apps, however, I found the documentation was very hard to understand on their website.

I know there are some famous apps using Electron, e.g Slack, Wordpress and Github Desktop. I wonder if they are really using Spectron or something else as automation to test their apps.

Pretty much I just want to figure out if Spectron is the only way to test Electron.

Zoe The Paranoid
  • 412
  • 5
  • 11
  • 1
    "I just want to figure out if Spectron is the only way to test Electron." ... No, there are other testing frameworks for Electron too. For example, I know that the commercial testing framework QF-Test can test electron apps, see . – quant Feb 28 '19 at 08:07

2 Answers2

8

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

kontrollanten
  • 2,229
  • 13
  • 28
2

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);   
slckayhn
  • 1,083
  • 11
  • 20