|
| 1 | +// @ts-check |
| 2 | +const { defineConfig, devices } = require('@playwright/test'); |
| 3 | + |
| 4 | +/** |
| 5 | + * Playwright Configuration for Production Visual Regression Tests |
| 6 | + * |
| 7 | + * This config is specifically for testing the production site at |
| 8 | + * https://demo.propertywebbuilder.com and its theme subdomains. |
| 9 | + * |
| 10 | + * Usage: |
| 11 | + * # Run all production visual tests |
| 12 | + * npx playwright test --config=playwright.production.config.js |
| 13 | + * |
| 14 | + * # Update snapshots after intentional changes |
| 15 | + * npx playwright test --config=playwright.production.config.js --update-snapshots |
| 16 | + * |
| 17 | + * # Run specific test file |
| 18 | + * npx playwright test --config=playwright.production.config.js tests/e2e/visual/production.spec.js |
| 19 | + */ |
| 20 | + |
| 21 | +module.exports = defineConfig({ |
| 22 | + // Only run visual regression tests for production |
| 23 | + testDir: './tests/e2e/visual', |
| 24 | + testMatch: ['**/*.spec.js'], |
| 25 | + |
| 26 | + // Snapshot settings |
| 27 | + snapshotDir: './tests/e2e/visual/snapshots', |
| 28 | + snapshotPathTemplate: '{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{ext}', |
| 29 | + |
| 30 | + // Don't run tests in parallel to avoid rate limiting |
| 31 | + fullyParallel: false, |
| 32 | + workers: 1, |
| 33 | + |
| 34 | + // Fail the build on CI if you accidentally left test.only in the source code |
| 35 | + forbidOnly: !!process.env.CI, |
| 36 | + |
| 37 | + // Retry failed tests (useful for flaky network conditions) |
| 38 | + retries: process.env.CI ? 2 : 1, |
| 39 | + |
| 40 | + // Reporter configuration |
| 41 | + reporter: [ |
| 42 | + ['html', { outputFolder: 'playwright-report-production', open: 'never' }], |
| 43 | + ['list'], |
| 44 | + ], |
| 45 | + |
| 46 | + // Global test timeout (production sites may be slower) |
| 47 | + timeout: 60000, |
| 48 | + |
| 49 | + // Expect timeout for assertions |
| 50 | + expect: { |
| 51 | + timeout: 10000, |
| 52 | + // Default screenshot comparison settings |
| 53 | + toHaveScreenshot: { |
| 54 | + maxDiffPixelRatio: 0.05, |
| 55 | + threshold: 0.2, |
| 56 | + animations: 'disabled', |
| 57 | + }, |
| 58 | + }, |
| 59 | + |
| 60 | + // Shared settings for all projects |
| 61 | + use: { |
| 62 | + // No baseURL - tests use full URLs for different subdomains |
| 63 | + baseURL: undefined, |
| 64 | + |
| 65 | + // Collect trace when retrying the failed test |
| 66 | + trace: 'on-first-retry', |
| 67 | + |
| 68 | + // Screenshot on failure |
| 69 | + screenshot: 'only-on-failure', |
| 70 | + |
| 71 | + // Video on retry |
| 72 | + video: 'on-first-retry', |
| 73 | + |
| 74 | + // Longer navigation timeout for production |
| 75 | + navigationTimeout: 30000, |
| 76 | + |
| 77 | + // Action timeout |
| 78 | + actionTimeout: 15000, |
| 79 | + }, |
| 80 | + |
| 81 | + // Configure projects for different browsers/devices |
| 82 | + projects: [ |
| 83 | + { |
| 84 | + name: 'chromium', |
| 85 | + use: { |
| 86 | + ...devices['Desktop Chrome'], |
| 87 | + viewport: { width: 1440, height: 900 }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + { |
| 91 | + name: 'firefox', |
| 92 | + use: { |
| 93 | + ...devices['Desktop Firefox'], |
| 94 | + viewport: { width: 1440, height: 900 }, |
| 95 | + }, |
| 96 | + }, |
| 97 | + { |
| 98 | + name: 'webkit', |
| 99 | + use: { |
| 100 | + ...devices['Desktop Safari'], |
| 101 | + viewport: { width: 1440, height: 900 }, |
| 102 | + }, |
| 103 | + }, |
| 104 | + // Mobile Chrome |
| 105 | + { |
| 106 | + name: 'mobile-chrome', |
| 107 | + use: { |
| 108 | + ...devices['Pixel 5'], |
| 109 | + }, |
| 110 | + }, |
| 111 | + // Mobile Safari |
| 112 | + { |
| 113 | + name: 'mobile-safari', |
| 114 | + use: { |
| 115 | + ...devices['iPhone 13'], |
| 116 | + }, |
| 117 | + }, |
| 118 | + ], |
| 119 | + |
| 120 | + // Output folder for test artifacts |
| 121 | + outputDir: 'test-results-production', |
| 122 | +}); |
0 commit comments