/** * 客户管理 E2E 测试 (修正版) */ import { test, expect } from '@playwright/test'; test.describe('客户管理', () => { test.beforeEach(async ({ page }) => { await page.goto('/customers'); await page.waitForLoadState('networkidle'); }); test('新版客户页信息架构可见', async ({ page }) => { await expect(page.getByTestId('customers-page')).toBeVisible({ timeout: 5000 }); await expect(page.getByRole('heading', { name: '客户管理' })).toBeVisible(); await expect(page.getByTestId('customers-summary')).toBeVisible(); await expect(page.getByTestId('customers-table-card')).toBeVisible(); }); test('客户列表正确加载', async ({ page }) => { await expect(page.locator('.el-table').first()).toBeVisible({ timeout: 5000 }); await expect(page.getByRole('button', { name: '新增客户' })).toBeVisible(); }); test('新增客户完整流程', async ({ page }) => { await page.getByRole('button', { name: '新增客户' }).click(); await expect(page.locator('.el-dialog')).toBeVisible({ timeout: 3000 }); const timestamp = Date.now(); await page.getByPlaceholder('请输入客户公司名称').fill(`E2E测试客户_${timestamp}`); await page.getByPlaceholder('所属行业').fill('自动化测试'); await page.getByPlaceholder('联系人姓名').fill('张测试'); // 选择客户级别 await page.locator('.el-dialog .el-select').first().click(); await page.waitForTimeout(500); // 选项: A级重点 / B级普通 / C级长尾 await page.getByRole('option').first().click(); // 提交 await page.locator('.el-dialog__footer').getByRole('button', { name: /确|保存|提交/ }).click(); await expect(page.locator('.el-dialog')).not.toBeVisible({ timeout: 5000 }); }); test('关键词搜索客户', async ({ page }) => { const searchInput = page.getByPlaceholder(/搜索|客户名称|关键词/); if (await searchInput.isVisible()) { await searchInput.fill('中石化'); await page.getByRole('button', { name: '搜索' }).click(); await page.waitForTimeout(1000); await expect(page.locator('.el-table').first()).toBeVisible(); } }); test('查看客户档案详情', async ({ page }) => { const viewBtn = page.locator('.el-table').getByRole('button', { name: '查看档案' }).first(); if (await viewBtn.isVisible({ timeout: 3000 })) { await viewBtn.click(); await page.waitForURL(/customers\/detail/); } }); test('编辑客户信息', async ({ page }) => { const editBtn = page.locator('.el-table').getByRole('button', { name: '编辑' }).first(); if (await editBtn.isVisible({ timeout: 3000 })) { await editBtn.click(); await expect(page.locator('.el-dialog')).toBeVisible({ timeout: 3000 }); } }); test('分页翻页', async ({ page }) => { const pagination = page.locator('.el-pagination'); if (await pagination.isVisible()) { const nextBtn = pagination.locator('.btn-next'); if (await nextBtn.isEnabled()) { await nextBtn.click(); await page.waitForTimeout(1000); await expect(page.locator('.el-table').first()).toBeVisible(); } } }); });