Skip to content

Commit 558c646

Browse files
committed
replace Spectron by Playwright
1 parent 6463897 commit 558c646

15 files changed

+1535
-1442
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ testem.log
4343
/e2e/*.js
4444
!/e2e/protractor.conf.js
4545
/e2e/*.map
46+
/e2e/tracing
47+
/e2e/screenshots
4648

4749
# System Files
4850
.DS_Store

app/main.ts

-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import * as path from 'path';
33
import * as fs from 'fs';
44
import * as url from 'url';
55

6-
// Initialize remote module
7-
require('@electron/remote/main').initialize();
8-
96
let win: BrowserWindow = null;
107
const args = process.argv.slice(1),
118
serve = args.some(val => val === '--serve');
@@ -25,7 +22,6 @@ function createWindow(): BrowserWindow {
2522
nodeIntegration: true,
2623
allowRunningInsecureContent: (serve) ? true : false,
2724
contextIsolation: false, // false if you want to run e2e test with Spectron
28-
enableRemoteModule : true // true if you want to run e2e test with Spectron or use remote module in renderer context (ie. Angular)
2925
},
3026
});
3127

app/package-lock.json

+5-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
"version": "10.1.0",
44
"main": "main.js",
55
"private": true,
6-
"dependencies": {
7-
"@electron/remote": "1.2.0"
8-
}
6+
"dependencies": {}
97
}

e2e/common-setup.ts

-26
This file was deleted.

e2e/main.e2e.ts

-27
This file was deleted.

e2e/main.spec.ts

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright';
2+
import { test, expect } from '@playwright/test';
3+
const PATH = require('path');
4+
5+
test.describe('Check Home Page', async () => {
6+
let app: ElectronApplication;
7+
let firstWindow: Page;
8+
let context: BrowserContext;
9+
10+
test.beforeAll( async () => {
11+
app = await electron.launch({ args: [PATH.join(__dirname, '../app/main.js'), PATH.join(__dirname, '../app/package.json')] });
12+
context = app.context();
13+
await context.tracing.start({ screenshots: true, snapshots: true });
14+
firstWindow = await app.firstWindow();
15+
});
16+
17+
test('Launch electron app', async () => {
18+
19+
const windowState: { isVisible: boolean; isDevToolsOpened: boolean; isCrashed: boolean } = await app.evaluate(async (process) => {
20+
const mainWindow = process.BrowserWindow.getAllWindows()[0];
21+
22+
const getState = () => ({
23+
isVisible: mainWindow.isVisible(),
24+
isDevToolsOpened: mainWindow.webContents.isDevToolsOpened(),
25+
isCrashed: mainWindow.webContents.isCrashed(),
26+
});
27+
28+
return new Promise((resolve) => {
29+
if (mainWindow.isVisible()) {
30+
resolve(getState());
31+
} else {
32+
mainWindow.once('ready-to-show', () => setTimeout(() => resolve(getState()), 0));
33+
}
34+
});
35+
});
36+
37+
expect(windowState.isVisible).toBeTruthy();
38+
expect(windowState.isDevToolsOpened).toBeFalsy();
39+
expect(windowState.isCrashed).toBeFalsy();
40+
});
41+
42+
test('Check Home Page design', async ({ browserName}) => {
43+
// Uncomment if you change the design of Home Page in order to create a new screenshot
44+
const screenshot = await firstWindow.screenshot({ path: '/tmp/home.png' });
45+
expect(screenshot).toMatchSnapshot(`home-${browserName}.png`);
46+
});
47+
48+
test('Check title', async () => {
49+
const elem = await firstWindow.$('app-home h1');
50+
const text = await elem.innerText();
51+
expect(text).toBe('App works !');
52+
});
53+
54+
test.afterAll( async () => {
55+
await context.tracing.stop({ path: 'e2e/tracing/trace.zip' });
56+
await app.close();
57+
});
58+
});
Loading

e2e/playwright.config.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** @type {import('@playwright/test').PlaywrightTestConfig} */
2+
const config = {
3+
testDir: '.',
4+
timeout: 45000,
5+
outputDir: './screenshots',
6+
use: {
7+
headless: false,
8+
viewport: { width: 1280, height: 720 },
9+
launchOptions: {
10+
slowMo: 1000,
11+
},
12+
trace: 'on',
13+
},
14+
expect: {
15+
toMatchSnapshot: { threshold: 0.2 },
16+
},
17+
};
18+
19+
module.exports = config;

e2e/tsconfig.e2e.json

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
{
2-
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"outDir": "../out-tsc/e2e",
5-
"module": "commonjs",
6-
"types": [
7-
"mocha",
8-
"node"
9-
]
10-
},
11-
"include": [
12-
"**.ts"
13-
]
14-
}
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../out-tsc/e2e",
5+
"module": "commonjs",
6+
"types": [
7+
"node"
8+
]
9+
},
10+
"include": [
11+
"**.spec.ts"
12+
],
13+
}

0 commit comments

Comments
 (0)