-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
157 lines (135 loc) · 3.89 KB
/
playwright.config.ts
File metadata and controls
157 lines (135 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { defineConfig, devices } from '@playwright/test';
/**
* Playwright Configuration for Dither & Etch (2026 Best Practices)
*
* Configures test runners for accessibility, performance, and SEO testing.
* Features:
* - Multi-browser testing (Chrome, Firefox, Safari)
* - Light and dark mode testing
* - Mobile responsiveness testing
* - Parallel execution for speed
* - Comprehensive reporting
* - Modern locator strategies
* - Enhanced debugging capabilities
* - Dynamic port assignment to avoid conflicts
*/
// Use Astro's default preview port (4321) when TEST_PORT is not set
const PORT = process.env.TEST_PORT || '4321';
const BASE_URL = `http://localhost:${PORT}`;
export default defineConfig({
testDir: './tests',
// Output directory for test artifacts
outputDir: 'test-results',
// Run tests in parallel for speed (2026 best practice)
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 for stability
retries: process.env.CI ? 2 : 0,
// Optimize workers for 2026 hardware - 75% utilization for faster CI
workers: process.env.CI ? '75%' : '50%',
// Enhanced reporter configuration for comprehensive test results
reporter: [
[
'html',
{
outputFolder: 'playwright-report',
open: process.env.CI ? 'never' : 'on-failure',
},
],
['json', { outputFile: 'test-results/results.json' }],
['list'],
['junit', { outputFile: 'test-results/junit.xml' }],
],
// Global test configuration with 2026 enhancements
use: {
// Base URL for the preview server
baseURL: BASE_URL,
// Enhanced trace configuration for debugging
trace: process.env.CI ? 'retain-on-failure' : 'on-first-retry',
// Enhanced screenshot configuration
screenshot: {
mode: 'only-on-failure',
fullPage: true,
},
// Enhanced video configuration for CI debugging
video: process.env.CI ? 'retain-on-failure' : 'off',
// 2026 best practice: increased timeout for complex apps
actionTimeout: 15000,
navigationTimeout: 30000,
// Enhanced viewport configuration
viewport: { width: 1280, height: 720 },
// Ignore HTTPS errors for local development
ignoreHTTPSErrors: !process.env.CI,
},
// Expect configuration for consistent assertions
expect: {
timeout: 5000, // Stricter generic assertion timeout for snappier failure feedback
toHaveScreenshot: { maxDiffPixelRatio: 0.05 },
},
// Configure projects for cross-browser and viewport testing
projects: [
// Desktop browsers - light and dark mode
{
name: 'chromium-light',
use: {
...devices['Desktop Chrome'],
colorScheme: 'light',
},
},
{
name: 'chromium-dark',
use: {
...devices['Desktop Chrome'],
colorScheme: 'dark',
},
},
{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
},
},
{
name: 'webkit',
use: {
...devices['Desktop Safari'],
},
},
// Mobile devices for responsive testing
{
name: 'mobile-chrome',
use: {
...devices['Pixel 7'],
},
},
{
name: 'mobile-safari',
use: {
...devices['iPhone 14'],
},
},
// Tablet testing
{
name: 'tablet',
use: {
...devices['iPad Pro 11'],
},
},
// High-end Android (2026 Standard)
{
name: 'mobile-android-high',
use: {
...devices['Pixel 7'], // Or update to Pixel 9/10 equivalents if key available, safely fallback to 7 as "modern"
defaultBrowserType: 'chromium',
},
},
],
// Run the preview server before starting tests
webServer: {
command: `npm run build && npm run preview -- --port ${PORT}`,
port: parseInt(PORT, 10),
reuseExistingServer: !process.env.CI,
timeout: 120000,
},
});