chore: Spectron for e2e tests

This commit is contained in:
Artem Vasiliev
2019-03-01 15:07:37 +03:00
parent 3b9b80822f
commit 901438aab4
8 changed files with 79 additions and 77 deletions

View File

@@ -125,13 +125,6 @@
"root": "e2e",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "angular-electron:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {

View File

@@ -1,15 +0,0 @@
import { AngularElectronPage } from './app.po';
import { browser, element, by } from 'protractor';
describe('angular-electron App', () => {
let page: AngularElectronPage;
beforeEach(() => {
page = new AngularElectronPage();
});
it('should display message saying App works !', () => {
page.navigateTo('/');
expect(element(by.css('app-home h1')).getText()).toMatch('App works !');
});
});

View File

@@ -1,8 +0,0 @@
import { browser, element, by } from 'protractor';
/* tslint:disable */
export class AngularElectronPage {
navigateTo(route: string) {
return browser.get(route);
}
}

41
e2e/common-setup.ts Normal file
View File

@@ -0,0 +1,41 @@
const Application = require('spectron').Application;
const electronPath = require('electron'); // Require Electron from the binaries included in node_modules.
const path = require('path');
export default function setup() {
beforeEach(async function () {
this.app = new Application({
// Your electron path can be any binary
// i.e for OSX an example path could be '/Applications/MyApp.app/Contents/MacOS/MyApp'
// But for the sake of the example we fetch it from our node_modules.
path: electronPath,
// Assuming you have the following directory structure
// |__ my project
// |__ ...
// |__ main.js
// |__ package.json
// |__ index.html
// |__ ...
// |__ test
// |__ spec.js <- You are here! ~ Well you should be.
// The following line tells spectron to look and use the main.js file
// and the package.json located 1 level above.
args: [path.join(__dirname, '..')],
webdriverOptions: {}
});
await this.app.start();
const browser = this.app.client;
await browser.waitUntilWindowLoaded();
browser.timeouts('script', 15000);
});
afterEach(function () {
if (this.app && this.app.isRunning()) {
return this.app.stop();
}
});
}

28
e2e/main.spec.ts Normal file
View File

@@ -0,0 +1,28 @@
import {expect, assert} from 'chai';
import {SpectronClient} from 'spectron';
import commonSetup from './common-setup';
describe('angular-electron App', function () {
commonSetup.apply(this);
let browser: any;
let client: SpectronClient;
beforeEach(function () {
client = this.app.client;
browser = client as any;
});
it('should display message saying App works !', async function () {
const text = await browser.getText('app-home h1');
expect(text).to.equal('App works !');
});
it('creates initial windows', async function () {
const count = await client.getWindowCount();
expect(count).to.equal(2);
});
});

View File

@@ -1,37 +0,0 @@
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 25000,
delayBrowserTimeInSeconds: 0,
specs: [
'./**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: ["--no-sandbox", "--headless", "--disable-gpu"]
}
},
chromeOnly: true,
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function () { },
realtimeFailure: true
},
useAllAngular2AppRoots: true,
beforeLaunch: function () {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});