article-management.spec.js 2.5 KB

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