dingdanquanliucheng/e2e/playwright.config.js
2026-06-14 16:20:04 +08:00

102 lines
2.1 KiB
JavaScript

// @ts-check
const { defineConfig, devices } = require('@playwright/test');
/**
* Playwright E2E 测试配置
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
// 测试目录
testDir: './tests',
// 测试文件匹配模式
testMatch: '**/*.spec.js',
// 全局超时时间(毫秒)
timeout: 60000,
// 每个测试的超时时间
expect: {
timeout: 10000,
},
// 完全并行运行
fullyParallel: true,
// CI 环境下禁止 test.only
forbidOnly: !!process.env.CI,
// 失败重试次数
retries: process.env.CI ? 2 : 0,
// 并行 worker 数量
workers: process.env.CI ? 1 : undefined,
// 报告器配置
reporter: [
['html', { outputFolder: 'playwright-report' }],
['json', { outputFile: 'test-results.json' }],
['list'],
],
// 全局设置
use: {
// 基础 URL
baseURL: process.env.BASE_URL || 'http://localhost:5173',
// 截图策略
screenshot: 'only-on-failure',
// 视频录制
video: 'retain-on-failure',
// 追踪
trace: 'on-first-retry',
// 默认导航超时
navigationTimeout: 30000,
// 默认操作超时
actionTimeout: 10000,
},
// 项目配置(不同浏览器)
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
// 可选:其他浏览器
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },
],
// Web 服务器配置(自动启动前端开发服务器)
webServer: [
{
command: 'cd ../frontend/web-admin && npm run dev',
port: 5173,
timeout: 120000,
reuseExistingServer: !process.env.CI,
env: {
VITE_API_BASE_URL: process.env.API_BASE_URL || 'http://localhost:8000',
},
},
{
command: 'cd ../frontend/web-sales && npm run dev',
port: 5174,
timeout: 120000,
reuseExistingServer: !process.env.CI,
env: {
VITE_API_BASE_URL: process.env.API_BASE_URL || 'http://localhost:8000',
},
},
],
});