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.
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