playwright.config.js
1.87 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
/*
* @Date: 2026-01-28 21:45:00
* @Description: Playwright E2E 测试配置
*/
import { defineConfig, devices } from '@playwright/test'
export default defineConfig({
// 测试文件位置
testDir: './e2e',
// 测试超时时间(毫秒)
timeout: 30 * 1000,
// 期望超时时间
expect: {
timeout: 5 * 1000,
},
// 失败时重试次数
retries: process.env.CI ? 2 : 0,
// 并行执行
workers: process.env.CI ? 1 : undefined,
// 报告器
reporter: [
['html', { outputFolder: 'playwright-report' }],
['json', { outputFile: 'test-results/test-results.json' }],
['junit', { outputFile: 'test-results/test-results.xml' }],
],
// 共享配置
use: {
// 基础 URL(开发服务器地址)
baseURL: 'http://localhost:5173',
// 追踪失败测试(用于调试)
trace: 'on-first-retry',
// 截图(仅失败时)
screenshot: 'only-on-failure',
// 视频录制(仅失败时)
video: 'retain-on-failure',
// 浏览器视口大小(移动端优先)
viewport: { width: 375, height: 667 },
// 忽略 HTTPS 错误
ignoreHTTPSErrors: true,
// 操作超时
actionTimeout: 10 * 1000,
navigationTimeout: 30 * 1000,
},
// 测试项目(不同浏览器和视口)
projects: [
{
name: 'chromium-mobile',
use: {
...devices['iPhone 12'],
browserName: 'chromium',
},
},
{
name: 'chromium-desktop',
use: {
...devices['Desktop Chrome'],
viewport: { width: 1280, height: 720 },
},
},
{
name: 'webkit-mobile',
use: {
...devices['iPhone 12'],
browserName: 'webkit',
},
},
],
// 开发服务器(测试前启动)
webServer: {
command: 'pnpm dev',
url: 'http://localhost:5173',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
},
})