- SRE-QA Skills 擴充 - CLAUDE.md 指引更新 - playwright.config.ts 優化 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { defineConfig, devices } from '@playwright/test'
|
||
|
||
/**
|
||
* Playwright E2E 測試配置
|
||
* =======================
|
||
* Phase VI: 截圖 + 錄影自動產出
|
||
*/
|
||
|
||
// Phase 20: 支持環境變數覆蓋 baseURL,可針對生產環境測試
|
||
const baseURL = process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:3000'
|
||
const isRemote = baseURL !== 'http://localhost:3000'
|
||
|
||
export default defineConfig({
|
||
testDir: './tests/e2e',
|
||
fullyParallel: true,
|
||
forbidOnly: !!process.env.CI,
|
||
retries: process.env.CI ? 2 : 0,
|
||
workers: process.env.CI ? 1 : undefined,
|
||
reporter: [
|
||
['html', { outputFolder: 'test-results/html-report' }],
|
||
['list'],
|
||
],
|
||
|
||
use: {
|
||
// Base URL for navigation (可通過 PLAYWRIGHT_BASE_URL 環境變數覆蓋)
|
||
baseURL,
|
||
|
||
// 截圖與錄影 - 統帥強制要求
|
||
screenshot: 'on',
|
||
video: 'on',
|
||
trace: 'on-first-retry',
|
||
|
||
// Viewport
|
||
viewport: { width: 1920, height: 1080 },
|
||
|
||
// Timeouts
|
||
actionTimeout: 10000,
|
||
navigationTimeout: 30000,
|
||
},
|
||
|
||
// Output directory for screenshots and videos
|
||
outputDir: 'test-results',
|
||
|
||
projects: [
|
||
{
|
||
name: 'chromium',
|
||
use: { ...devices['Desktop Chrome'] },
|
||
},
|
||
],
|
||
|
||
// Web server configuration - start Next.js dev server
|
||
// 當使用遠端 URL (PLAYWRIGHT_BASE_URL) 時跳過本地 dev server
|
||
...(isRemote ? {} : {
|
||
webServer: {
|
||
command: 'pnpm dev',
|
||
url: 'http://localhost:3000',
|
||
reuseExistingServer: !process.env.CI,
|
||
timeout: 120000,
|
||
},
|
||
}),
|
||
})
|