Skip to content

Commit 00c6eb0

Browse files
committed
Migrate from Protractor and Pupeteer to Playwright #8336
Protractor is EOL, and Playwright can replace entirely Pupeteer (for our usage for Karma). This simplify a bit the maintenance since we can install system deps automatically, and we are sure that everything is always synced. For now we only test on Chromium, because that's what we always did, but we could also test other browsers later.
1 parent 674dce7 commit 00c6eb0

14 files changed

+676
-550
lines changed

.github/workflows/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- run: ./node_modules/.bin/ng test natural --progress false --watch=false --browsers ChromeHeadlessCustom
3131
- run: ./node_modules/.bin/ng test natural-editor --progress false --watch=false --browsers ChromeHeadlessCustom
3232
- run: ./node_modules/.bin/ng test demo --progress false --watch=false --browsers ChromeHeadlessCustom
33+
- run: yarn e2e
3334

3435
lint:
3536
runs-on: ubuntu-latest

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# compiled output
44
/dist
55
/tmp
6+
/logs/
67
/out-tsc
78
# Only exists if Bazel was run
89
/bazel-out

angular.json

-15
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,6 @@
101101
"tsConfig": ["tsconfig.app.json", "tsconfig.spec.json", "e2e/tsconfig.json"],
102102
"exclude": ["**/node_modules/**"]
103103
}
104-
},
105-
"e2e": {
106-
"builder": "@angular-devkit/build-angular:protractor",
107-
"options": {
108-
"protractorConfig": "e2e/protractor.conf.js"
109-
},
110-
"configurations": {
111-
"production": {
112-
"devServerTarget": "demo:serve:production"
113-
},
114-
"development": {
115-
"devServerTarget": "demo:serve:development"
116-
}
117-
},
118-
"defaultConfiguration": "development"
119104
}
120105
}
121106
},

e2e/protractor.conf.js

-30
This file was deleted.

e2e/src/app.e2e-spec.ts

-25
This file was deleted.

e2e/src/app.po.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import {browser, by, element} from 'protractor';
1+
import {Page} from '@playwright/test';
22

33
export class AppPage {
4-
public navigateTo(): Promise<any> {
5-
return browser.get(browser.baseUrl) as Promise<any>;
6-
}
4+
constructor(private readonly page: Page) {}
75

86
public getTitleText(): Promise<string> {
9-
return element(by.css('app-root h1')).getText() as Promise<string>;
7+
return this.page.innerText('app-root h1');
108
}
119
}

e2e/src/app.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {expect, test} from '@playwright/test';
2+
3+
import {AppPage} from './app.po';
4+
5+
test.describe('workspace-project App', () => {
6+
let app: AppPage;
7+
8+
test.describe('as anonymous', () => {
9+
test.beforeEach(async ({page}) => {
10+
app = new AppPage(page);
11+
});
12+
13+
test('should display welcome message', async ({page}) => {
14+
await page.goto('/');
15+
expect(await app.getTitleText()).toEqual('@ecodev/natural');
16+
});
17+
});
18+
});

e2e/tsconfig.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
{
2-
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"outDir": "../out-tsc/e2e",
5-
"module": "commonjs",
6-
"target": "es2018",
7-
"types": ["jasmine", "jasminewd2", "node"]
8-
}
2+
"extends": "../tsconfig.json"
93
}

karma.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Karma configuration file, see link for more information
22
// https://karma-runner.github.io/1.0/config/configuration-file.html
33

4-
// Use puppeteer to control a headless Chrome
5-
process.env.CHROME_BIN = require('puppeteer').executablePath();
4+
// Use Playwright Chromium
5+
process.env.CHROME_BIN = require('@playwright/test').chromium.executablePath();
66

77
module.exports = function (config) {
88
config.set({

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
"license": "MIT",
55
"scripts": {
66
"ng": "ng",
7+
"postinstall": "playwright install chromium",
78
"dev": "ln -fs ../../bin/pre-commit.sh .git/hooks/pre-commit && ng serve",
89
"test-natural": "ng test natural",
910
"test-natural-editor": "ng test natural-editor",
1011
"test-demo": "ng test demo",
1112
"lint": "ng lint",
12-
"e2e": "ng e2e",
13+
"e2e": "playwright test",
1314
"build-lib": "yarn build-natural && yarn build-natural-editor",
1415
"build-natural": "ng build natural && cp -rv README.md dist/natural/ && cd dist/natural && yarn version --no-git-tag-version --new-version `git describe --tags --always`",
1516
"build-natural-editor": "ng build natural-editor && cd dist/natural-editor && yarn version --no-git-tag-version --new-version `git describe --tags --always`",
@@ -56,6 +57,7 @@
5657
"@angular/cli": "^12.2.9",
5758
"@angular/compiler-cli": "^12.2.9",
5859
"@angular/language-service": "^12.2.9",
60+
"@playwright/test": "^1.17.1",
5961
"@types/jasmine": "~3.9.1",
6062
"@types/jasminewd2": "^2.0.10",
6163
"@types/lodash-es": "^4.17.5",
@@ -78,8 +80,6 @@
7880
"karma-jasmine-html-reporter": "^1.7.0",
7981
"ng-packagr": "^12.2.2",
8082
"prettier": "2.4.1",
81-
"protractor": "~7.0.0",
82-
"puppeteer": "^12.0.1",
8383
"ts-node": "^10.2.1",
8484
"tslint": "~6.1.0",
8585
"typescript": "~4.3.5"

playwright.config.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {PlaywrightTestConfig} from '@playwright/test';
2+
3+
const config: PlaywrightTestConfig = {
4+
testDir: './e2e/',
5+
outputDir: __dirname + '/logs/tests/e2e/',
6+
use: {
7+
baseURL: process.env.E2E_BASE_URL ?? 'http://localhost:4201/',
8+
headless: true,
9+
viewport: {width: 1280, height: 720},
10+
ignoreHTTPSErrors: true,
11+
screenshot: 'on',
12+
video: {
13+
mode: 'on',
14+
size: {
15+
width: 1280,
16+
height: 720,
17+
},
18+
},
19+
},
20+
webServer: {
21+
command: 'yarn dev',
22+
port: 4201,
23+
timeout: 120 * 1000,
24+
reuseExistingServer: !process.env.CI,
25+
},
26+
};
27+
28+
export default config;

projects/natural-editor/karma.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Karma configuration file, see link for more information
22
// https://karma-runner.github.io/1.0/config/configuration-file.html
33

4-
// Use puppeteer to control a headless Chrome
5-
process.env.CHROME_BIN = require('puppeteer').executablePath();
4+
// Use Playwright Chromium
5+
process.env.CHROME_BIN = require('@playwright/test').chromium.executablePath();
66

77
module.exports = function (config) {
88
config.set({

projects/natural/karma.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Karma configuration file, see link for more information
22
// https://karma-runner.github.io/1.0/config/configuration-file.html
33

4-
// Use puppeteer to control a headless Chrome
5-
process.env.CHROME_BIN = require('puppeteer').executablePath();
4+
// Use Playwright Chromium
5+
process.env.CHROME_BIN = require('@playwright/test').chromium.executablePath();
66

77
module.exports = function (config) {
88
config.set({

0 commit comments

Comments
 (0)