Skip to content

Commit 82eb285

Browse files
authored
Merge pull request #2344 from headlamp-k8s/playwright-test-modes
Initial Playwright E2E Test for App Mode in Electron
2 parents d12693b + 262aa6a commit 82eb285

9 files changed

+557
-13
lines changed

app/e2e-tests/.gitignore

+5
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/

app/e2e-tests/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# e2e test for local playwright app mode
2+
3+
Currently we have the original e2e tests for the web mode in the `e2e-tests` directory. We are adding new tests for the app mode in the `app-e2e-tests` directory for local testing. Unlike the other tests, these tests do not require a token to run so the setup is as followed:
4+
5+
## Running app mode tests
6+
7+
## Setup
8+
9+
- Before running the tests, be sure to have an instance of Minikube running with the name `minikube`
10+
11+
### Running the tests
12+
13+
To run the tests for the app mode, follow the steps below:
14+
15+
- cd into the e2e-tests directory within the headlamp repository
16+
`cd headlamp/app/e2e-tests`
17+
18+
- npm install the needed packages
19+
`npm install`
20+
21+
- run the following command
22+
`npm run test-app`
23+
(optional: include `-- --headed` to run the tests in headed mode)
24+
(optional: include `-- --ui` to run the tests in ui mode)
25+
26+
## Running web mode tests
27+
28+
Running the tests for the web mode requires the backend and frontend to be running. Follow the steps below to run the tests for the web mode:
29+
30+
Note: You may encouter issues switching from the app mode tests to the web mode tests. If you do, search for any running headlamp server processes and end them before running the web mode tests or app mode tests.
31+
32+
## Setup
33+
34+
- Before running the tests, be sure to have an instance of Minikube running with the name `minikube`
35+
36+
### Backend
37+
38+
To run the tests for the web mode, you will need to have the backend running. Follow the steps below to run the backend:
39+
40+
- cd into the headlamp directory in a singular terminal
41+
`cd headlamp`
42+
43+
- run the following command
44+
`make backend` followed by `make run-backend`
45+
46+
### Frontend
47+
48+
To run the tests for the web mode, you will need to have the frontend running. Follow the steps below to run the frontend:
49+
50+
- cd into the headlamp directory in a separate terminal
51+
`cd headlamp/frontend`
52+
53+
- run the following command
54+
`make frontend` followed by `make run-frontend`
55+
56+
### Running the tests
57+
58+
To run the tests for the web mode, follow the steps below:
59+
60+
- cd into the e2e-tests directory within the headlamp repository in a separate terminal
61+
`cd headlamp/app/e2e-tests`
62+
63+
- npm install the needed packages
64+
`npm install`
65+
66+
- run the following command
67+
`npm run test-web`
68+
(optional: include `-- --headed` to run the tests in headed mode)
69+
(optional: include `-- --ui` to run the tests in ui mode)

app/e2e-tests/package-lock.json

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

app/e2e-tests/package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "e2e-tests",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"test-app": "PLAYWRIGHT_TEST_MODE=app playwright test",
7+
"test-web": "PLAYWRIGHT_TEST_MODE=web playwright test"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"description": "",
13+
"devDependencies": {
14+
"@playwright/test": "^1.48.1",
15+
"@types/node": "^22.7.5"
16+
}
17+
}

app/e2e-tests/playwright.config.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// import dotenv from 'dotenv';
8+
// import path from 'path';
9+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
10+
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: './tests',
16+
/* Run tests in files in parallel */
17+
timeout: 60 * 1000,
18+
expect: {
19+
/**
20+
* Maximum time expect() should wait for the condition to be met.
21+
* For example in `await expect(locator).toHaveText();`
22+
*/
23+
timeout: 120000,
24+
},
25+
fullyParallel: false,
26+
/* Fail the build on CI if you accidentally left test.only in the source code. */
27+
forbidOnly: !!process.env.CI,
28+
/* Retry on CI only */
29+
retries: process.env.CI ? 2 : 0,
30+
/* Opt out of parallel tests on CI. */
31+
workers: 1,
32+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
33+
reporter: 'html',
34+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
35+
use: {
36+
/* Base URL to use in actions like `await page.goto('/')`. */
37+
// baseURL: 'http://127.0.0.1:3000',
38+
39+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
40+
trace: 'on-first-retry',
41+
},
42+
43+
/* Configure projects for major browsers */
44+
projects: [
45+
{
46+
name: 'chromium',
47+
use: { ...devices['Desktop Chrome'] },
48+
},
49+
],
50+
51+
/* Run your local dev server before starting the tests */
52+
// webServer: {
53+
// command: 'npm run start',
54+
// url: 'http://127.0.0.1:3000',
55+
// reuseExistingServer: !process.env.CI,
56+
// },
57+
});

0 commit comments

Comments
 (0)