import { defineConfig, devices } from '@playwright/test'; /** * Playwright Configuration * * This configuration follows best practices for E2E testing: * - Retries for flaky test handling * - Parallel execution for speed * - Screenshots and traces on failure * - Multiple browser support */ export default defineConfig({ // Test directory testDir: './tests', // Maximum time one test can run timeout: 30 * 1000, // Run tests 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 : 1, // Number of parallel workers workers: process.env.CI ? 1 : undefined, // Reporter to use reporter: [ ['html'], ['list'], // Add JUnit reporter for CI ...(process.env.CI ? [['junit', { outputFile: 'test-results/junit.xml' }]] : []), ], // Shared settings for all projects use: { // Base URL to use in actions like `await page.goto('/')` baseURL: process.env.BASE_URL || 'http://localhost:3000', // Collect trace when retrying the failed test trace: 'on-first-retry', // Take screenshot on failure screenshot: 'only-on-failure', // Capture video on first retry video: 'retain-on-failure', // Maximum time for each action (e.g., click, fill) actionTimeout: 10 * 1000, // Maximum time for navigation actions navigationTimeout: 30 * 1000, }, // 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 dev', // url: 'http://localhost:3000', // reuseExistingServer: !process.env.CI, // timeout: 120 * 1000, // }, });