Files
novalon-manage-system/novalon-manage-web/playwright.config.ts
T
张翔 9609745ead test(e2e): 修复测试套件并提升通过率至97.30%
- 更新网关配置以符合Spring Boot 3.x最佳实践
- 修复数据字典和系统配置测试的UI元素定位问题
- 改进Playwright测试配置,增加超时时间和日志
- 新增TestDataCleaner工具类用于测试数据清理
- 更新全局设置使用test profile禁用签名验证

测试通过率从59.57%提升至97.30%,提升了37.73%
2026-04-28 20:10:44 +08:00

124 lines
3.3 KiB
TypeScript

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:3002';
export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 1,
workers: process.env.CI ? 4 : '50%',
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: 'setup',
testMatch: /.*\.setup\.ts/,
},
{
name: 'smoke',
testDir: './e2e/smoke',
testMatch: /.*\.spec\.ts/,
use: {
...devices['Desktop Chrome'],
launchOptions: {
args: [
'--disable-blink-features=AutomationControlled',
'--disable-dev-shm-usage',
'--no-sandbox'
]
}
},
},
{
name: 'journeys',
testDir: './e2e/journeys',
testMatch: /.*\.spec\.ts/,
dependencies: ['setup'],
use: {
...devices['Desktop Chrome'],
storageState: 'playwright/.auth/user.json',
launchOptions: {
args: [
'--disable-blink-features=AutomationControlled',
'--disable-dev-shm-usage',
'--no-sandbox'
]
}
},
},
{
name: 'debug',
testDir: './e2e/debug',
testMatch: /.*\.spec\.ts/,
dependencies: ['setup'],
use: {
...devices['Desktop Chrome'],
storageState: 'playwright/.auth/user.json',
launchOptions: {
args: [
'--disable-blink-features=AutomationControlled',
'--disable-dev-shm-usage',
'--no-sandbox'
]
}
},
},
],
webServer: {
command: 'npm run dev',
url: 'http://localhost:3002',
reuseExistingServer: !process.env.CI,
timeout: 180000,
stdout: 'pipe',
stderr: 'pipe',
reuseExistingServerTimeout: 10000
},
globalSetup: path.resolve(__dirname, './e2e/global-setup.ts'),
globalTeardown: path.resolve(__dirname, './e2e/global-teardown.ts'),
});