const { test, expect } = require('@playwright/test'); const BASE_URL = 'https://ajy.danclub.cn'; const TEST_ADMIN = { username: 'admin', password: 'admin123' }; test.describe('4.1 设备列表', () => { 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('DM-001: 查看设备列表', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); await page.waitForTimeout(1000); }); test('DM-002: 按设备编号搜索', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); const searchInput = page.getByPlaceholder('请输入设备编号'); if (await searchInput.isVisible()) { await searchInput.fill('AJY001'); await page.getByRole('button', { name: '查询' }).click(); await page.waitForTimeout(1000); } }); test('DM-003: 按设备名称搜索', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); }); test('DM-004: 按绑定用户搜索', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); }); test('DM-005: 按在线状态筛选', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); }); }); test.describe('4.2 新增设备', () => { 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('DM-010: 成功新增设备', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); const addBtn = page.getByRole('button', { name: '新增' }); if (await addBtn.isVisible()) { await addBtn.click(); await page.waitForTimeout(500); } }); test('DM-011: 设备编号必填验证', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); 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('DM-012: 设备编号唯一性验证', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); }); }); test.describe('4.3 设备用户管理', () => { 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('DM-020: 查看设备绑定用户', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); }); test('DM-021: 添加用户到设备', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); }); test('DM-022: 设置主用户', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); }); test('DM-023: 解绑用户', async ({ page }) => { await page.goto(`${BASE_URL}/#/device`); await page.waitForLoadState('networkidle'); }); }); test.describe('5.1 管理员管理', () => { 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('SY-001: 查看管理员列表', async ({ page }) => { await page.goto(`${BASE_URL}/#/system`); await page.waitForLoadState('networkidle'); await page.waitForTimeout(1000); }); test('SY-002: 新增管理员', async ({ page }) => { await page.goto(`${BASE_URL}/#/system`); await page.waitForLoadState('networkidle'); const addBtn = page.getByRole('button', { name: '新增管理员' }); if (await addBtn.isVisible()) { await addBtn.click(); await page.waitForTimeout(500); } }); test('SY-003: 用户名唯一性验证', async ({ page }) => { await page.goto(`${BASE_URL}/#/system`); await page.waitForLoadState('networkidle'); }); test('SY-004: 密码格式验证', async ({ page }) => { await page.goto(`${BASE_URL}/#/system`); await page.waitForLoadState('networkidle'); }); test('SY-005: 禁用管理员', async ({ page }) => { await page.goto(`${BASE_URL}/#/system`); await page.waitForLoadState('networkidle'); }); test('SY-006: 启用管理员', async ({ page }) => { await page.goto(`${BASE_URL}/#/system`); await page.waitForLoadState('networkidle'); }); }); test.describe('5.2 操作日志', () => { 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('SY-010: 查看操作日志', async ({ page }) => { await page.goto(`${BASE_URL}/#/system/log`); await page.waitForLoadState('networkidle'); await page.waitForTimeout(1000); }); test('SY-011: 按操作人筛选', async ({ page }) => { await page.goto(`${BASE_URL}/#/system/log`); await page.waitForLoadState('networkidle'); }); test('SY-012: 按操作类型筛选', async ({ page }) => { await page.goto(`${BASE_URL}/#/system/log`); await page.waitForLoadState('networkidle'); }); test('SY-013: 按时间范围筛选', async ({ page }) => { await page.goto(`${BASE_URL}/#/system/log`); await page.waitForLoadState('networkidle'); }); test('SY-014: 导出日志', async ({ page }) => { await page.goto(`${BASE_URL}/#/system/log`); await page.waitForLoadState('networkidle'); }); });