const { test, expect } = require('@playwright/test'); const BASE_URL = 'https://ajy.danclub.cn'; const TEST_ADMIN = { username: 'admin', password: 'admin123' }; test.describe('内容管理测试', () => { test.beforeEach(async ({ page }) => { await page.goto(BASE_URL); await page.waitForLoadState('networkidle'); await page.getByPlaceholder('请输入用户名').fill(TEST_ADMIN.username); await page.getByPlaceholder('请输入密码').fill(TEST_ADMIN.password); await page.getByRole('button', { name: '登 录' }).click(); await page.waitForURL(`${BASE_URL}/#/user/app`, { timeout: 10000 }); }); test('CM-001: 查看文章列表', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); await page.waitForTimeout(1000); }); test('CM-002: 按标题搜索文章', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); const searchInput = page.getByPlaceholder('请输入文章标题'); if (await searchInput.isVisible()) { await searchInput.fill('艾灸'); await page.getByRole('button', { name: '查询' }).click(); await page.waitForTimeout(1000); } }); test('CM-003: 按分类筛选文章', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); }); test('CM-004: 按状态筛选文章', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); }); test('CM-010: 新增文章-必填验证', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); const addBtn = page.getByRole('button', { name: '新增' }); if (await addBtn.isVisible()) { await addBtn.click(); await page.waitForTimeout(500); await page.getByRole('button', { name: '保存' }).click(); await page.waitForTimeout(500); } }); test('CM-011: 文章标题超长验证', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); }); test('CM-012: 发布文章', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); const addBtn = page.getByRole('button', { name: '新增' }); if (await addBtn.isVisible()) { await addBtn.click(); await page.waitForTimeout(500); } }); test('CM-013: 编辑文章', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); const editBtn = page.getByRole('button', { name: '编辑' }).first(); if (await editBtn.isVisible()) { await editBtn.click(); await page.waitForTimeout(500); } }); test('CM-014: 删除文章', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); }); test('CM-015: 审核文章', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); }); test('CM-016: 批量发布文章', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); const checkbox = page.locator('.el-table__header .el-checkbox').first(); if (await checkbox.isVisible()) { await checkbox.click(); await page.waitForTimeout(300); } }); test('CM-017: 文章分页切换', async ({ page }) => { await page.goto(`${BASE_URL}/#/content`); await page.waitForLoadState('networkidle'); const nextButton = page.locator('.btn-next').first(); if (await nextButton.isVisible()) { await nextButton.click(); await page.waitForTimeout(1000); } }); });