import { defineConfig, devices } from '@playwright/test'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const isHeadless = process.env.PLAYWRIGHT_HEADLESS === 'true' || process.env.CI === 'true'; const baseURL = process.env.TEST_BASE_URL || process.env.VITE_BASE_URL || 'http://localhost:3001'; export default defineConfig({ testDir: './e2e', fullyParallel: true, forbidOnly: !!process.env.CI, retries: 3, workers: process.env.CI ? 2 : 4, reporter: [ ['html', { outputFolder: 'playwright-report' }], ['json', { outputFile: 'test-results/results.json' }], ['junit', { outputFile: 'test-results/junit.xml' }], ['list'], ['./e2e/customReporter.ts'] ], timeout: 120000, expect: { timeout: 30000, toHaveScreenshot: { threshold: 0.2 }, toMatchSnapshot: { threshold: 0.2 } }, use: { baseURL: baseURL, trace: process.env.CI ? 'retain-on-failure' : 'on-first-retry', screenshot: 'only-on-failure', video: process.env.CI ? 'retain-on-failure' : 'on-first-retry', actionTimeout: 30000, navigationTimeout: 60000, headless: isHeadless, locale: 'zh-CN', timezoneId: 'Asia/Shanghai', ignoreHTTPSErrors: true, bypassCSP: true, viewport: { width: 1280, height: 720 }, launchOptions: { slowMo: process.env.CI ? 0 : 100 }, contextOptions: { permissions: ['geolocation'], geolocation: { latitude: 35.6895, longitude: 139.6917 }, userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' } }, projects: [ { name: 'chromium', use: { ...devices['Desktop Chrome'], launchOptions: { args: [ '--disable-blink-features=AutomationControlled', '--disable-dev-shm-usage', '--no-sandbox' ] } }, }, { name: 'firefox', use: { ...devices['Desktop Firefox'], launchOptions: { firefoxUserPrefs: { 'dom.webdriver.enabled': false, 'useAutomationExtension': false } } }, }, { name: 'webkit', use: { ...devices['Desktop Safari'] }, }, { name: 'Mobile Chrome', use: { ...devices['Pixel 5'], launchOptions: { args: [ '--disable-blink-features=AutomationControlled', '--disable-dev-shm-usage' ] } }, }, ], webServer: { command: 'npm run dev', url: 'http://localhost:3001', reuseExistingServer: !process.env.CI, timeout: 120000, stdout: 'pipe', stderr: 'pipe' }, globalSetup: path.resolve(__dirname, './e2e/global-setup.ts'), globalTeardown: path.resolve(__dirname, './e2e/global-teardown.ts'), });