playwright.config.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { defineConfig, devices } from '@playwright/test';
  2. import { existsSync } from 'node:fs';
  3. import { fileURLToPath } from 'node:url';
  4. /* 本机配置:.env(模板 .env.example)。已在环境里的同名变量优先,不会被覆盖 */
  5. const envFile = fileURLToPath(new URL('.env', import.meta.url));
  6. if (existsSync(envFile)) process.loadEnvFile(envFile);
  7. /**
  8. * dashboard-v6 端到端测试配置
  9. * 文档: https://playwright.dev/docs/test-configuration
  10. *
  11. * 前置:dev server 需已启动
  12. * cd ../api-v13 && php artisan serve
  13. * cd ../dashboard-v6 && npm run dev
  14. */
  15. export default defineConfig({
  16. testDir: './src/tests',
  17. /* 本项目是对开发环境的手工测试替代,串行执行更贴近真人操作,日志也更好读 */
  18. fullyParallel: false,
  19. workers: 1,
  20. forbidOnly: !!process.env.CI,
  21. retries: process.env.CI ? 2 : 0,
  22. timeout: 90_000,
  23. expect: { timeout: 15_000 },
  24. reporter: [['list'], ['html', { outputFolder: 'playwright-report', open: 'never' }]],
  25. use: {
  26. baseURL: process.env.E2E_BASE || 'http://127.0.0.1:4000/pcd-v2026/',
  27. viewport: { width: 1600, height: 1000 },
  28. trace: 'retain-on-failure',
  29. video: 'retain-on-failure',
  30. actionTimeout: 30_000,
  31. },
  32. projects: [
  33. /* 登录一次,把会话存到 playwright/.auth/user.json */
  34. { name: 'setup', testMatch: /.*\.setup\.ts/ },
  35. {
  36. name: 'chromium',
  37. use: {
  38. ...devices['Desktop Chrome'],
  39. storageState: 'playwright/.auth/user.json',
  40. },
  41. dependencies: ['setup'],
  42. },
  43. ],
  44. });