| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /**
- * ================================================================
- * 场景:文章管理 E2E 测试
- * ================================================================
- * 目标:管理员通过 cfc-web Element UI 管理后台管理文章
- * 部署地址:http://cfc.iwintrue.com/admin
- *
- * 路由映射:
- * 文章列表 → /article-manage
- * 文章分类 → /article-categories
- * ================================================================
- */
- const { test, expect } = require('@playwright/test');
- async function ensureLoggedIn(page) {
- const sidebar = page.locator('.sidebar-container, .el-menu-vertical-demo, .el-aside');
- if (await sidebar.isVisible({ timeout: 3000 }).catch(() => false)) {
- return;
- }
- await page.goto('/login');
- await page.waitForSelector('.el-input__inner', { timeout: 15000 });
- await page.fill('.el-input__inner', 'admin', { timeout: 5000 });
- const passwordInputs = page.locator('.el-input__inner').filter({ hasPlaceholder: /密码/ });
- if (await passwordInputs.count() > 0) {
- await passwordInputs.first().fill('admin123');
- } else {
- const inputs = page.locator('.el-input__inner');
- const count = await inputs.count();
- if (count >= 2) {
- await inputs.nth(1).fill('admin123');
- }
- }
- await page.click('.el-button--primary.login-btn, .el-button[type="primary"]:not(.skip)');
- await page.waitForURL(/\/dashboard|\/admin\/dashboard/, { timeout: 15000 });
- }
- test.describe('【场景流程】文章管理全流程', () => {
- test('[场景1] 管理员查看文章列表 - 期望返回文章列表', async ({ page }) => {
- await ensureLoggedIn(page);
- await page.goto('/article-manage');
- await page.waitForLoadState('networkidle');
- await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
- const rows = page.locator('.el-table__body tr');
- const count = await rows.count();
- expect(count).toBeGreaterThanOrEqual(0);
- });
- test('[场景2] 管理员管理文章分类 - 期望分类页面可用', async ({ page }) => {
- await ensureLoggedIn(page);
- await page.goto('/article-categories');
- await page.waitForLoadState('networkidle');
- await expect(page.locator('.el-table, .category-list')).toBeVisible({ timeout: 10000 });
- });
- test('[场景3] 管理员查看知识标签', async ({ page }) => {
- await ensureLoggedIn(page);
- await page.goto('/knowledge-tags');
- await page.waitForLoadState('networkidle');
- await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
- });
- });
|