Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

61 Zeilen
2.0 KiB

  1. import { defineConfig, devices } from '@playwright/test'
  2. import fs from 'node:fs'
  3. import path from 'node:path'
  4. function loadLocalEnvironment() {
  5. const filename = process.env.E2E_ENV_FILE?.trim() || path.resolve('.env')
  6. if (!fs.existsSync(filename)) return
  7. for (const line of fs.readFileSync(filename, 'utf8').split(/\r?\n/)) {
  8. const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/)
  9. if (!match || process.env[match[1]!]) continue
  10. const raw = match[2]!
  11. process.env[match[1]!] = raw.length >= 2
  12. && ((raw.startsWith('"') && raw.endsWith('"')) || (raw.startsWith("'") && raw.endsWith("'")))
  13. ? raw.slice(1, -1)
  14. : raw
  15. }
  16. }
  17. loadLocalEnvironment()
  18. const safeRunId = (process.env.APE2E_RUN_ID || 'manual')
  19. .replace(/[^A-Za-z0-9._-]+/g, '-')
  20. .slice(0, 80) || 'manual'
  21. const runDirectory = path.resolve('artifacts', 'runs', safeRunId)
  22. const baseURL = (process.env.BASE_URL ?? 'http://127.0.0.1:8003').replace(/\/$/, '')
  23. const browserChannel = process.env.E2E_BROWSER_CHANNEL?.trim()
  24. export default defineConfig({
  25. testDir: './tests',
  26. outputDir: path.join(runDirectory, 'test-results'),
  27. fullyParallel: false,
  28. workers: 1,
  29. retries: process.env.CI ? 1 : 0,
  30. timeout: 90_000,
  31. expect: { timeout: 12_000 },
  32. reporter: [
  33. ['list'],
  34. ['html', { outputFolder: path.join(runDirectory, 'html-report'), open: 'never' }],
  35. ['json', { outputFile: path.join(runDirectory, 'results.json') }],
  36. ],
  37. use: {
  38. baseURL,
  39. locale: 'zh-CN',
  40. timezoneId: 'Asia/Shanghai',
  41. actionTimeout: 12_000,
  42. navigationTimeout: 30_000,
  43. screenshot: 'off',
  44. // 测试使用真实密码、API Key 与一次性密钥;不生成可能包含输入快照的 trace/video。
  45. // 成功与失败场景都由 fixtures.ts 生成经过遮罩控制的截图。
  46. trace: 'off',
  47. video: 'off',
  48. },
  49. projects: [{
  50. name: 'chromium',
  51. use: {
  52. ...devices['Desktop Chrome'],
  53. ...(browserChannel ? { channel: browserChannel } : {}),
  54. },
  55. }],
  56. })