playwright.config.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { defineConfig, devices } from '@playwright/test'
  2. /**
  3. * Playwright E2E 测试配置
  4. * @see https://playwright.dev/docs/test-configuration
  5. */
  6. export default defineConfig({
  7. // 测试目录
  8. testDir: './e2e',
  9. // 测试文件匹配模式
  10. testMatch: '**/*.spec.ts',
  11. // 并行执行
  12. fullyParallel: true,
  13. // CI 环境下禁止 only
  14. forbidOnly: !!process.env.CI,
  15. // 失败重试次数
  16. retries: process.env.CI ? 2 : 0,
  17. // 并行工作线程数
  18. workers: process.env.CI ? 1 : undefined,
  19. // 报告器
  20. reporter: [
  21. ['html', { outputFolder: 'playwright-report' }],
  22. ['list']
  23. ],
  24. // 全局配置
  25. use: {
  26. // 基础 URL
  27. baseURL: 'http://localhost:8000',
  28. // 收集失败时的追踪信息
  29. trace: 'on-first-retry',
  30. // 截图
  31. screenshot: 'only-on-failure',
  32. // 视频录制
  33. video: 'on-first-retry',
  34. },
  35. // 浏览器配置
  36. projects: [
  37. {
  38. name: 'chromium',
  39. use: { ...devices['Desktop Chrome'] },
  40. },
  41. ],
  42. // 启动开发服务器
  43. webServer: {
  44. command: 'pnpm dev',
  45. url: 'http://localhost:8000',
  46. reuseExistingServer: !process.env.CI,
  47. timeout: 120 * 1000,
  48. },
  49. })