Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ develop, master ]
pull_request:
branches: [ develop, master ]
jobs:
test:
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Docker Compose
run: sudo apt-get update && sudo apt-get install -y docker-compose
- name: Prepare for tests run
run: cd e2e-tests && npm run docker:build
- name: Run Playwright tests
run: cd e2e-tests && npm run docker:test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: e2e-tests/playwright-report/
retention-days: 30
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,33 @@ export default {
```
Demo data should have at least 32 dcm files (slices).

## E2E testing

### Overview
E2E testing is based on Playwright framework. Tests execution is configured to run in Chrome browser on Linux OS using docker.

### Run tests locally in docker
It needs to update screenshots or to check the result in same environment as in CI/CD pipeline.

1. Open terminal
2. Go to e2e-tests folder - `cd e2e-tests`
3. Prepare project for testing - `npm run docker:build`
4. Run test in docker
- Using "test" script to see the test result and log - `test=<test_file_name>:<test_row_number> npm run docker:test` (e.g. `test=test.spec.ts:10 npm run docker:test`)
- Using "test:update" script to generate screenshots - `test=<test_file_name>:<test_row_number> npm run docker:test:update` (e.g. `test=test.spec.ts:10 npm run docker:test:update`)

### Debug tests locally without docker
It needs to go through the tests step by step and visually check the test behaviour in the browser.

1. Open terminal
2. Go to e2e-tests folder - `cd e2e-tests`
3. Run test in debug mode locally without docker - `npm run test:debug -- <test_file_name>:<test_row_number>` (e.g. `npm run test:debug -- test1.spec.ts:10`)
- If you see such error please follow the instructions provided in it and install playwrite locally
![error-tests-exec-1.png](docs/images/error-tests-exec-1.png)

### Additional information

#### Detailed commands description
- `npm run docker:build` will create docker images for application and for testing. It will also run scripts to prepare environment (install dependencies for application and testing and build application).
- `[test=<test_file_name>:<test_row_number>] npm run docker:test` will run tests in docker container.
- `[test=<test_file_name>:<test_row_number>] npm run docker:test:updage` will run tests in docker container and generate screenshots if it does not exist or differs from existing one.
Binary file added docs/images/error-tests-exec-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions e2e-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Playwright
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
5 changes: 5 additions & 0 deletions e2e-tests/Dockerfile-app
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:20-bullseye-slim

RUN apt update && apt install -y curl

WORKDIR /mriviewer
3 changes: 3 additions & 0 deletions e2e-tests/Dockerfile-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mcr.microsoft.com/playwright:v1.50.1-jammy

WORKDIR /mriviewer-tests
4 changes: 4 additions & 0 deletions e2e-tests/app_prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -ex
npm i
npm run build
27 changes: 27 additions & 0 deletions e2e-tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'
services:
mriviewer-app:
build:
context: ./
dockerfile: ./Dockerfile-app
volumes:
- ../:/mriviewer
command: [ "npm", "run", "serve" ] # Start the server
ports:
- "3000:3000"
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:3000" ] # Adjust port if needed
interval: 1s
retries: 10

mriviewer-autotests:
depends_on:
mriviewer-app:
condition: service_healthy # Ensure the app is ready before tests r
build:
context: ./
dockerfile: ./Dockerfile-tests
container_name: mriviewer-e2e-tests
volumes:
- ./:/mriviewer-tests

92 changes: 92 additions & 0 deletions e2e-tests/package-lock.json

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

21 changes: 21 additions & 0 deletions e2e-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "e2e-tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "npx playwright test",
"test:debug": "npx playwright test --debug",
"test:update": "npx playwright test --update-snapshots --",
"docker:build": "docker-compose build --no-cache && docker-compose run --rm mriviewer-app bash e2e-tests/app_prepare.sh && docker-compose run --rm mriviewer-autotests bash test_prepare.sh && docker-compose down",
"docker:test": "docker-compose run --rm mriviewer-autotests bash test_run.sh $test && docker-compose down",
"docker:test:update": "docker-compose run --rm mriviewer-autotests bash test_update.sh $test && docker-compose down"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.50.1",
"@types/node": "^22.13.1",
"playwright": "^1.50.1"
}
}
86 changes: 86 additions & 0 deletions e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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') });
Comment on lines +3 to +9
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* 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') });

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is default generated comment. We are not going to introduce env variables in current PR


/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* 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: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
[
'html',
{
open: 'never',
},
],
],
/* 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: 'off',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
trace: 'off',
trace: 'on-first-retry',
screenshot: 'only-on-failure',

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traces increase the report size dramatically. According to my experience they are not so useful because every report contains test steps log and it is easy to run it locally with debug option if needed (usually not often). So I'm going to keep it off in this PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections

},

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

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
//
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: '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,
// },
});
3 changes: 3 additions & 0 deletions e2e-tests/test_prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
set -ex
npm i
2 changes: 2 additions & 0 deletions e2e-tests/test_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
npm run test "$@"
2 changes: 2 additions & 0 deletions e2e-tests/test_update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
npm run test:update "$@"
5 changes: 5 additions & 0 deletions e2e-tests/tests/helpers/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Page } from '@playwright/test';

export function openHomePage(page: Page) {
return page.goto('http://mriviewer-app:3000');
}
21 changes: 21 additions & 0 deletions e2e-tests/tests/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test, expect } from '@playwright/test';
import { openHomePage } from './helpers/page';

test('has title', async ({ page }) => {
await openHomePage(page);

await expect(page).toHaveTitle(/MRI Viewer Dicom 2d\/3d browser/);
});

test('should open initial screen view', async ({ page }) => {
await openHomePage(page);

await expect(page).toHaveScreenshot();
});

test('should open dialog with demo data', async ({ page }) => {
await openHomePage(page);
await page.getByText('Demo Data').click();

await expect(page).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading