The transporter does not work well with Electron, as it does not have access to electron-specific APIs, and rendering cannot be properly controlled. Spectron , on the other hand, is specifically designed for Electron and has an API very similar to Protractor. This gives you the opportunity to simultaneously test both basic and rendering processes.
I had to copy some code from Protractor so that it waited for Angular 2 to load. (Pay no attention if you are not using Angular.) Here is a working example:
const path = require('path'); const electron = require('electron-prebuilt'); var Application = require('spectron').Application var assert = require('assert') let appPath = path.join(__dirname, '..', 'dist'); function awaitAngular2(client) { client.timeoutsAsyncScript(5000); // From: https://github.com/angular/protractor/blob/master/lib/clientsidescripts.js // Returns a promise that resolves when all of Angular 2 components are loaded and stable return client.executeAsync(function(done) { try { var testabilities = window.getAllAngularTestabilities(); var count = testabilities.length; var decrement = function() { count--; if (count === 0) { done(); } }; testabilities.forEach(function(testability) { testability.whenStable(decrement); }); } catch (err) { done(err.message); } }); } describe('application launch', function () { this.timeout(10000) beforeEach(function () { this.app = new Application({ path: electron, args: [appPath] }); return this.app.start().then(() => { return awaitAngular2(this.app.client); }) }); afterEach(function () { if (this.app && this.app.isRunning()) { return this.app.stop() } }); it('shows an initial window', function () { return this.app.client.getWindowCount().then(function (count) { assert.equal(count, 1) }) }); it('shows a headline', function () { this.app.client.getText('app-banner h1').then(function (bannerText) { assert.equal(bannerText, 'Tour of Heroes'); }) }); });
If you have several .spec files that you want to run automatically, you can integrate them using Jasmine or Mocha Node.js.
source share