activity-registration.spec.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * ================================================================
  3. * 场景:活动管理 E2E 测试
  4. * ================================================================
  5. * 目标:管理员通过 cfc-web Element UI 管理后台管理活动
  6. * 部署地址:http://cfc.iwintrue.com/admin
  7. *
  8. * 路由映射:
  9. * 活动列表 → /activities
  10. * 活动编辑 → /activity-edit
  11. * 活动审核 → /activity-review
  12. * 报名审核 → /activity-registration-review
  13. * ================================================================
  14. */
  15. const { test, expect } = require('@playwright/test');
  16. async function ensureLoggedIn(page) {
  17. const sidebar = page.locator('.sidebar-container, .el-menu-vertical-demo, .el-aside');
  18. if (await sidebar.isVisible({ timeout: 3000 }).catch(() => false)) {
  19. return;
  20. }
  21. await page.goto('/login');
  22. await page.waitForSelector('.el-input__inner', { timeout: 15000 });
  23. await page.fill('.el-input__inner', 'admin', { timeout: 5000 });
  24. const passwordInputs = page.locator('.el-input__inner').filter({ hasPlaceholder: /密码/ });
  25. if (await passwordInputs.count() > 0) {
  26. await passwordInputs.first().fill('admin123');
  27. } else {
  28. const inputs = page.locator('.el-input__inner');
  29. const count = await inputs.count();
  30. if (count >= 2) {
  31. await inputs.nth(1).fill('admin123');
  32. }
  33. }
  34. await page.click('.el-button--primary.login-btn, .el-button[type="primary"]:not(.skip)');
  35. await page.waitForURL(/\/dashboard|\/admin\/dashboard/, { timeout: 15000 });
  36. }
  37. test.describe('【场景流程】活动管理全流程', () => {
  38. test('[场景1] 管理员查看活动列表', async ({ page }) => {
  39. await ensureLoggedIn(page);
  40. await page.goto('/activities');
  41. await page.waitForLoadState('networkidle');
  42. await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
  43. });
  44. test('[场景2] 管理员查看活动审核', async ({ page }) => {
  45. await ensureLoggedIn(page);
  46. await page.goto('/activity-review');
  47. await page.waitForLoadState('networkidle');
  48. await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
  49. });
  50. test('[场景3] 管理员查看报名审核', async ({ page }) => {
  51. await ensureLoggedIn(page);
  52. await page.goto('/activity-registration-review');
  53. await page.waitForLoadState('networkidle');
  54. await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
  55. });
  56. });