|
| 1 | +import { defineConfig, devices } from '@playwright/test'; |
| 2 | +import * as dotenv from 'dotenv'; |
| 3 | +import * as path from 'path'; |
| 4 | + |
| 5 | +dotenv.config(); |
| 6 | + |
| 7 | +/** |
| 8 | + * Unique project identifier for session isolation. |
| 9 | + * This ensures this project's Playwright instance doesn't conflict with other projects. |
| 10 | + */ |
| 11 | +const PROJECT_ID = 'spring-demo-app'; |
| 12 | + |
| 13 | +/** |
| 14 | + * Playwright configuration for Spring User Framework Demo App E2E tests. |
| 15 | + * @see https://playwright.dev/docs/test-configuration |
| 16 | + */ |
| 17 | +export default defineConfig({ |
| 18 | + testDir: './tests', |
| 19 | + |
| 20 | + /* Unique output directories for this project */ |
| 21 | + outputDir: path.join(__dirname, 'test-results', PROJECT_ID), |
| 22 | + |
| 23 | + /* Run tests in files in parallel */ |
| 24 | + fullyParallel: true, |
| 25 | + |
| 26 | + /* Fail the build on CI if you accidentally left test.only in the source code */ |
| 27 | + forbidOnly: !!process.env.CI, |
| 28 | + |
| 29 | + /* Retry on CI only */ |
| 30 | + retries: process.env.CI ? 2 : 0, |
| 31 | + |
| 32 | + /* Opt out of parallel tests on CI */ |
| 33 | + workers: process.env.CI ? 1 : undefined, |
| 34 | + |
| 35 | + /* Reporter to use */ |
| 36 | + reporter: [ |
| 37 | + ['html', { outputFolder: 'reports/html' }], |
| 38 | + ['json', { outputFile: 'reports/results.json' }], |
| 39 | + ['list'] |
| 40 | + ], |
| 41 | + |
| 42 | + /* Shared settings for all the projects below */ |
| 43 | + use: { |
| 44 | + /* Base URL to use in actions like `await page.goto('/')` */ |
| 45 | + baseURL: process.env.BASE_URL || 'http://localhost:8080', |
| 46 | + |
| 47 | + /* Collect trace when retrying the failed test */ |
| 48 | + trace: 'on-first-retry', |
| 49 | + |
| 50 | + /* Capture screenshot on failure */ |
| 51 | + screenshot: 'only-on-failure', |
| 52 | + |
| 53 | + /* Capture video on failure */ |
| 54 | + video: 'on-first-retry', |
| 55 | + |
| 56 | + /* Default timeout for actions */ |
| 57 | + actionTimeout: 10000, |
| 58 | + |
| 59 | + /* Default navigation timeout */ |
| 60 | + navigationTimeout: 30000, |
| 61 | + |
| 62 | + /* Session isolation: unique browser launch options per project */ |
| 63 | + launchOptions: { |
| 64 | + args: [ |
| 65 | + /* Disable shared memory usage for better isolation in containers/parallel runs */ |
| 66 | + '--disable-dev-shm-usage', |
| 67 | + /* Disable GPU to prevent shared resource conflicts */ |
| 68 | + '--disable-gpu', |
| 69 | + ], |
| 70 | + }, |
| 71 | + |
| 72 | + /* Unique context options for session isolation */ |
| 73 | + contextOptions: { |
| 74 | + /* Ignore HTTPS errors for local development */ |
| 75 | + ignoreHTTPSErrors: true, |
| 76 | + }, |
| 77 | + }, |
| 78 | + |
| 79 | + /* Configure global timeout */ |
| 80 | + timeout: 60000, |
| 81 | + |
| 82 | + /* Expect timeout */ |
| 83 | + expect: { |
| 84 | + timeout: 10000, |
| 85 | + }, |
| 86 | + |
| 87 | + /* Configure projects for major browsers */ |
| 88 | + projects: [ |
| 89 | + { |
| 90 | + name: 'chromium', |
| 91 | + use: { ...devices['Desktop Chrome'] }, |
| 92 | + }, |
| 93 | + |
| 94 | + { |
| 95 | + name: 'firefox', |
| 96 | + use: { ...devices['Desktop Firefox'] }, |
| 97 | + }, |
| 98 | + |
| 99 | + { |
| 100 | + name: 'webkit', |
| 101 | + use: { ...devices['Desktop Safari'] }, |
| 102 | + }, |
| 103 | + |
| 104 | + /* Test against mobile viewports */ |
| 105 | + { |
| 106 | + name: 'Mobile Chrome', |
| 107 | + use: { ...devices['Pixel 5'] }, |
| 108 | + }, |
| 109 | + |
| 110 | + { |
| 111 | + name: 'Mobile Safari', |
| 112 | + use: { ...devices['iPhone 12'] }, |
| 113 | + }, |
| 114 | + ], |
| 115 | + |
| 116 | + /* Run your local dev server before starting the tests */ |
| 117 | + webServer: { |
| 118 | + command: 'cd .. && ./gradlew bootRun --args="--spring.profiles.active=local,playwright-test"', |
| 119 | + url: 'http://localhost:8080', |
| 120 | + reuseExistingServer: !process.env.CI, |
| 121 | + timeout: 120000, |
| 122 | + stdout: 'pipe', |
| 123 | + stderr: 'pipe', |
| 124 | + }, |
| 125 | +}); |
0 commit comments