2
0

playwright.config.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { defineConfig, devices } from '@playwright/test';
  2. export default defineConfig({
  3. testDir: './specs',
  4. fullyParallel: true,
  5. forbidOnly: !!process.env.CI,
  6. retries: process.env.CI ? 2 : 0,
  7. workers: process.env.CI ? 1 : 4,
  8. // 缩短默认超时时间(Playwright 默认 30000ms),加快测试失败反馈
  9. timeout: 60000, // E2E 测试需要更长时间(多个下拉框操作)
  10. reporter: [
  11. ['html'],
  12. ['list'],
  13. ['junit', { outputFile: 'test-results/junit.xml' }]
  14. ],
  15. use: {
  16. baseURL: process.env.E2E_BASE_URL || 'http://localhost:8080',
  17. trace: 'on-first-retry',
  18. screenshot: 'only-on-failure',
  19. video: 'retain-on-failure',
  20. // 在每个测试前设置测试模式标志,使 Checkbox 组件使用原生版本
  21. initScripts: [
  22. '(() => { window.__PLAYWRIGHT_TEST__ = true; })()'
  23. ],
  24. },
  25. projects: [
  26. {
  27. name: 'chromium',
  28. use: { ...devices['Desktop Chrome'] },
  29. },
  30. {
  31. name: 'firefox',
  32. use: { ...devices['Desktop Firefox'] },
  33. },
  34. {
  35. name: 'webkit',
  36. use: { ...devices['Desktop Safari'] },
  37. },
  38. {
  39. name: 'Mobile Chrome',
  40. use: { ...devices['Pixel 5'] },
  41. },
  42. {
  43. name: 'Mobile Safari',
  44. use: { ...devices['iPhone 12'] },
  45. },
  46. ],
  47. webServer: {
  48. command: 'npm run dev',
  49. url: 'http://localhost:8080',
  50. reuseExistingServer: !process.env.CI,
  51. timeout: 120000,
  52. },
  53. });