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.
An open source framework for easily writing integrations tests for your Electron app. Spectron sets up and tears down your app and allows it to be test-driven remotely with full support for the Electron APIs. Built on top of ChromeDriver and WebDriverIO.
Start recording a test by going to Test > Record > Record Keyword Test. Expand the Recording toolbar, click Run App, and then select the Electron application. Create Property Checkpoints by clicking Add Check. Checkpoints verify objects and values in the application that's being tested.
Spectron is an open source framework that is used to easily write integration and end-to-end tests for your Electron applications. Simulating User Input, navigating web pages are some of the capabilities that Spectron provides.
It also simplifies the setup, running, and tearing down of the test environment for Electron. Through Spectron, you have the entire Electron API and Chromium API available within your tests. Thereby, we can test our Electron apps using ChromeDriver and WebdriverIO.
The main problem with testing Electron apps is the lack of established and updated frameworks. Virtually all guides recommend using Spectron. However, Spectron only supports Electron versions up to 13: newer versions do not work. And that makes it useless for my purposes.
We currently have several other recommended alternatives to Spectron, including Playwright and WebDriverIO. Official tutorials for each option can be found in our Automated Testing documentation. We here on the Electron team appreciate you using Spectron and Electron.
While Spectron has consistently put out new releases for each new version of Electron, the project has had very little maintenance and improvements for well over a year, and currently has no full-time maintainers.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With