-
Notifications
You must be signed in to change notification settings - Fork 103
Feature/EPMUII-10417 Configure e2e tests on playwright #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2dc4eff
60b91c3
020a55d
9fc2ae0
4213aba
1957792
49f77b0
efc294a
b99d430
fe4e9db
ffa7719
a452568
a3b3229
82057d9
d845ed4
a745ad7
aaff435
eee98cc
d6e2fe8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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/ |
| 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 |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/sh | ||
| set -ex | ||
| npm i | ||
| npm run build |
| 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 | ||
|
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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" | ||
| } | ||
| } |
| 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') }); | ||||||||
|
|
||||||||
| /** | ||||||||
| * 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', | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||||||||
| // }, | ||||||||
| }); | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/sh | ||
| set -ex | ||
| npm i |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/sh | ||
| npm run test "$@" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/sh | ||
| npm run test:update "$@" |
| 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'); | ||
| } |
| 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(); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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