playwright.config.live.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * Playwright 线上 UI 级 E2E 配置(针对已部署站点 cfc.iwintrue.com)
  3. * ================================================================
  4. * 与 playwright.config.js 的关键区别:
  5. * - **无 globalSetup**:默认配置的 globalSetup 会执行 reset-db.sh 重置共享测试库,
  6. * 对本配置(打生产/测试已部署站点)绝对禁止。
  7. * - 只做只读浏览器自动化:不写业务数据(唯一例外是登录,属只读会话建立)。
  8. * - workers=1、fullyParallel=false:单节点串行,符合「每个节点只能跑一个浏览器自动化任务」。
  9. * - 两个 project 按 spec 分流:admin 走桌面视口,frontend(小程序 H5)走移动视口。
  10. *
  11. * 运行(单节点、串行):
  12. * **cwd 必须是 tests/ 目录**(或走 tests/package.json 的 npm scripts):
  13. * cd tests && npx playwright test -c playwright.config.live.js --project=admin-desktop
  14. * cd tests && npx playwright test -c playwright.config.live.js --project=frontend-mobile
  15. * cd tests && npm run test:e2e:live:frontend
  16. *
  17. * ⚠️ 工具链双副本(R416 工具链守卫):
  18. * 仓库根 D:/cfc/node_modules 自带 @playwright/test(1.63.0,根 package.json),
  19. * 与 tests/node_modules(1.61.1)是两份物理副本。从仓库根直接 `npx playwright ...`
  20. * 时 CLI 用根副本、spec 的 require('@playwright/test') 落到 tests 副本,两套模块
  21. * 状态不共享 → 顶层 test.describe() 抛 "did not expect test.describe() to be called
  22. * here"、runner 报 "No tests found"(即历轮报告里的「test.describe 工具链信号」,
  23. * 如 R429 189 节点)。本配置加载时会自检双副本,命中即 fail-fast 并给出正确跑法。
  24. */
  25. var path = require('path');
  26. var LIVE_BASE = process.env.LIVE_BASE_URL || 'http://cfc.iwintrue.com';
  27. // ---------------------------------------------------------------------------
  28. // R416 · @playwright/test 双副本自检(工具链守卫)
  29. // 比对「进程 cwd 向上解析到的副本」与「本配置(tests/)解析到的副本」,
  30. // 不一致即说明 CLI 与 spec 各拿一份 @playwright/test → test.describe() 无法
  31. // 注册、假红 "No tests found"。fail-fast 并给出可执行的正确跑法。
  32. // ---------------------------------------------------------------------------
  33. (function assertSinglePlaywrightCopy() {
  34. var testsCopy = require.resolve('@playwright/test'); // 配置侧 → tests/node_modules
  35. var cwdCopy = testsCopy;
  36. try {
  37. cwdCopy = require.resolve('@playwright/test', { paths: [process.cwd()] });
  38. } catch (e) {
  39. // cwd 向上解析不到(如根未装 node_modules)→ 视为单副本,放行
  40. }
  41. if (path.resolve(cwdCopy) !== path.resolve(testsCopy)) {
  42. throw new Error(
  43. '[R416 工具链守卫] 检测到 @playwright/test 双物理副本:CLI(cwd=' + process.cwd() + ')→' + cwdCopy +
  44. ',tests/→' + testsCopy +
  45. '\n 两副本各自持有模块状态,spec 的 test.describe() 无法注册,runner 会假红 "No tests found"。' +
  46. '\n 正确跑法:cd tests && npx playwright test -c playwright.config.live.js --project=frontend-mobile' +
  47. '\n 或 npm run test:e2e:live:frontend(tests/ 下执行)'
  48. );
  49. }
  50. })();
  51. module.exports = {
  52. testDir: path.join(__dirname, 'e2e-live'),
  53. timeout: 150000,
  54. expect: { timeout: 15000 },
  55. retries: 0,
  56. workers: 1,
  57. fullyParallel: false,
  58. outputDir: path.join(__dirname, '.live-artifacts'),
  59. reporter: [['list']],
  60. use: {
  61. baseURL: LIVE_BASE,
  62. headless: true,
  63. ignoreHTTPSErrors: true,
  64. actionTimeout: 20000,
  65. navigationTimeout: 60000,
  66. screenshot: 'only-on-failure',
  67. trace: 'off',
  68. video: 'off',
  69. },
  70. projects: [
  71. {
  72. name: 'admin-desktop',
  73. testMatch: /admin-live\.spec\.js$/,
  74. use: { browserName: 'chromium', viewport: { width: 1440, height: 900 } },
  75. },
  76. {
  77. name: 'frontend-mobile',
  78. testMatch: /frontend-live\.spec\.js$/,
  79. use: { browserName: 'chromium', viewport: { width: 375, height: 812 }, isMobile: true, hasTouch: true },
  80. },
  81. {
  82. // 接口级契约(商城价格排序需求变更 S1):无需浏览器,走 request fixture 直连 /api
  83. name: 'shop-api',
  84. testMatch: /shop-sort-api\.spec\.js$/,
  85. use: { browserName: 'chromium' },
  86. },
  87. {
  88. // R138:D/X 桥接鉴权契约(TC-DX-U01/U02)。此前该 spec 存在于 e2e-live 却未挂入任何
  89. // project → 设计的用例从未被执行(覆盖缺口)。端点未部署时用例按 404 记 skip,
  90. // 不产生假绿;端点上线后自动转为 401/403 断言。
  91. name: 'dx-bridge',
  92. testMatch: /dx-health-bridge-auth\.spec\.js$/,
  93. use: { browserName: 'chromium' },
  94. },
  95. {
  96. // R260:法务页可达性契约(web/privacy.html · web/agreement.html,小米 HealthKit 上架所需)。
  97. // 窗口新增内容(5a0223b9a)尚无任何用例覆盖 → 补 TC-L-U01~U06,验证线上可达 + 结构完整。
  98. name: 'legal-pages',
  99. testMatch: /legal-pages-live\.spec\.js$/,
  100. use: { browserName: 'chromium', viewport: { width: 1440, height: 900 } },
  101. },
  102. {
  103. // R275:匿名访问鉴权门禁契约(TC-AU-U01~U10)。此前 B-227-1 连续 50 轮靠人工
  104. // curl 探针取证,不进入套件 → 修复后无人自动确认、也无法随 CI 回归。
  105. // 3 个私有点子为缺陷守卫(当前 200 保持红),5 个对照 + 2 个管理端为正向基线。
  106. name: 'auth-guard',
  107. testMatch: /auth-anonymous-guard\.spec\.js$/,
  108. use: { browserName: 'chromium' },
  109. },
  110. ],
  111. };