Skip to content

Commit

Permalink
Merge pull request #2344 from headlamp-k8s/playwright-test-modes
Browse files Browse the repository at this point in the history
Initial Playwright E2E Test for App Mode in Electron
  • Loading branch information
joaquimrocha authored Nov 27, 2024
2 parents d12693b + 262aa6a commit 82eb285
Show file tree
Hide file tree
Showing 9 changed files with 557 additions and 13 deletions.
5 changes: 5 additions & 0 deletions app/e2e-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
69 changes: 69 additions & 0 deletions app/e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# e2e test for local playwright app mode

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:

## Running app mode tests

## Setup

- Before running the tests, be sure to have an instance of Minikube running with the name `minikube`

### Running the tests

To run the tests for the app mode, follow the steps below:

- cd into the e2e-tests directory within the headlamp repository
`cd headlamp/app/e2e-tests`

- npm install the needed packages
`npm install`

- run the following command
`npm run test-app`
(optional: include `-- --headed` to run the tests in headed mode)
(optional: include `-- --ui` to run the tests in ui mode)

## Running web mode tests

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:

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.

## Setup

- Before running the tests, be sure to have an instance of Minikube running with the name `minikube`

### Backend

To run the tests for the web mode, you will need to have the backend running. Follow the steps below to run the backend:

- cd into the headlamp directory in a singular terminal
`cd headlamp`

- run the following command
`make backend` followed by `make run-backend`

### Frontend

To run the tests for the web mode, you will need to have the frontend running. Follow the steps below to run the frontend:

- cd into the headlamp directory in a separate terminal
`cd headlamp/frontend`

- run the following command
`make frontend` followed by `make run-frontend`

### Running the tests

To run the tests for the web mode, follow the steps below:

- cd into the e2e-tests directory within the headlamp repository in a separate terminal
`cd headlamp/app/e2e-tests`

- npm install the needed packages
`npm install`

- run the following command
`npm run test-web`
(optional: include `-- --headed` to run the tests in headed mode)
(optional: include `-- --ui` to run the tests in ui mode)
97 changes: 97 additions & 0 deletions app/e2e-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions app/e2e-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "e2e-tests",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test-app": "PLAYWRIGHT_TEST_MODE=app playwright test",
"test-web": "PLAYWRIGHT_TEST_MODE=web playwright test"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@playwright/test": "^1.48.1",
"@types/node": "^22.7.5"
}
}
57 changes: 57 additions & 0 deletions app/e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
timeout: 60 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 120000,
},
fullyParallel: false,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
Loading

0 comments on commit 82eb285

Please sign in to comment.