Skip to content

Commit 768ae5c

Browse files
authored
RHOAIENG-15152: feat(codeserver/e2e): add initial playwright e2e test project skeleton (#755)
* NO-ISSUE: feat(codeserver/e2e): add initial playwright project skeleton * NO-ISSUE: feat(codeserver/e2e): add a basic README.md * NO-ISSUE: add testcontainers as a dependency * NO-ISSUE: new customizable and flexible config * check env variables to determine how to run * take screenshots on failure * don't open annoying html report * disable parallel runs * exclude pnpm-lock.yaml from yamllint * move Playwright tests from codeserver/e2e to tests/browser * create a new containers folder for (future) testing of containers in Python
1 parent 9b84523 commit 768ae5c

File tree

7 files changed

+1193
-0
lines changed

7 files changed

+1193
-0
lines changed

ci/yamllint-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ rules:
66
line-length: disable
77
new-line-at-end-of-file:
88
level: warning
9+
10+
document-start:
11+
ignore:
12+
# generated file
13+
- 'pnpm-lock.yaml'

tests/browser/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/blob-report/
5+
/playwright/.cache/

tests/browser/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
This is a basic Playwright in Typescript that was setup like this
2+
3+
```shell
4+
brew install node pnpm
5+
pnpm create playwright
6+
```
7+
8+
## Getting started
9+
10+
Playwright needs to fetch its own versions of instrumented browsers.
11+
Run the following on your machine
12+
13+
```shell
14+
pnpm install
15+
pnpm exec playwright install
16+
```
17+
18+
It downloads Chromium, Firefox, Webkit, and also ffmpeg.
19+
20+
```commandline
21+
du -hs ${HOME}/Library/Caches/ms-playwright
22+
881M /Users/jdanek/Library/Caches/ms-playwrigh
23+
```
24+
25+
Use either the
26+
[VS Code Playwright extension](https://playwright.dev/docs/getting-started-vscode)
27+
or the IntelliJ one for nice UX.
28+
29+
Also try out [the UI mode](https://playwright.dev/docs/test-ui-mode) and the [codegen mode](https://playwright.dev/docs/codegen).
30+
31+
```shell
32+
pnpm playwright test --ui
33+
pnpm playwright codegen localhost:8787
34+
```
35+
36+
The main differentiators of Playwright are
37+
[auto-waiting](https://playwright.dev/docs/actionability),
38+
the browser fetching seen above,
39+
and integration and access to browser APIs (geolocation, ...).
40+
41+
Playwright test runner uses [fixtures](https://playwright.dev/docs/test-fixtures) injection, similarly to Pytest.
42+
43+
For debugging, run test with `--headed` and put `await page.pause()` somewhere the test.
44+
This only works when you "run" and not "run with debug" the test in the IDE.
45+
46+
The HTML report captures screenshot on failure, so maybe that's enough to figure out the failure.
47+
48+
CI captures execution traces that can be opened in [the trace viewer](https://playwright.dev/docs/trace-viewer) and explored.
49+
50+
```shell
51+
pnpm playwright show-trace path/to/trace.zip
52+
```
53+

tests/browser/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"private": "true",
3+
"name": "notebooks",
4+
"version": "1.0.0",
5+
"description": "Tests for Open Data Hub / OpenShift AI Notebook / Workbench images in TypeScript.",
6+
"main": "index.js",
7+
"scripts": {},
8+
"keywords": [],
9+
"author": "",
10+
"license": "MIT",
11+
"devDependencies": {
12+
"@playwright/test": "^1.48.2",
13+
"@types/node": "^22.8.1",
14+
"testcontainers": "^10.13.2"
15+
}
16+
}

tests/browser/playwright.config.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
import * as process from "node:process";
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// import dotenv from 'dotenv';
9+
// import path from 'path';
10+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
11+
12+
/**
13+
* See https://playwright.dev/docs/test-configuration.
14+
*/
15+
export default defineConfig({
16+
testDir: './tests',
17+
/* Run tests in files in parallel */
18+
fullyParallel: true,
19+
/* Fail the build on CI if you accidentally left test.only in the source code. */
20+
forbidOnly: !!process.env.CI,
21+
/* Retry on CI only */
22+
retries: process.env.CI ? 2 : 0,
23+
/* Opt out of parallel tests on CI. */
24+
workers: process.env.CI ? 1 : 1,
25+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
26+
reporter: [ ['html', { open: 'never' }], ['line'] ],
27+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
28+
use: {
29+
codeServerSource: {
30+
image: process.env['TEST_TARGET'],
31+
},
32+
33+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
34+
trace: 'on-first-retry',
35+
36+
// https://github.com/microsoft/playwright/issues/14854#issuecomment-1666185768
37+
screenshot: "only-on-failure",
38+
},
39+
40+
projects: getProjects(),
41+
42+
});
43+
44+
function getProjects() {
45+
if ('CI' in process.env) {
46+
/* Configure projects for major browsers */
47+
return [
48+
{
49+
name: 'chromium',
50+
use: {...devices['Desktop Chrome']},
51+
},
52+
53+
{
54+
name: 'firefox',
55+
use: {...devices['Desktop Firefox']},
56+
},
57+
58+
{
59+
name: 'webkit',
60+
use: {...devices['Desktop Safari']},
61+
}
62+
]
63+
}
64+
65+
/* Test against branded browsers. */
66+
return [
67+
{
68+
name: 'Google Chrome',
69+
use: { ...devices['Desktop Chrome'], channel: 'chrome',
70+
headless: false, // the CDP browser configured below is not affected by this
71+
/* custom properties, comment out as needed */
72+
connectCDP: 9222, // false | number: connect to an existing browser running at given port
73+
codeServerSource: { // prefers url if specified, otherwise will start the specified docker image
74+
// url: "", // not-present | string
75+
image: "quay.io/modh/codeserver:codeserver-ubi9-python-3.11-2024b-20241018", // string
76+
}
77+
},
78+
}
79+
]
80+
81+
}

0 commit comments

Comments
 (0)