| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- /**
- * ================================================================
- * 场景:供应商商品管理 E2E 测试
- * ================================================================
- * 用户故事:管理员可以管理供应商的商品列表,
- * 包括商品上架、下架、编辑、审核等操作。
- *
- * 流程步骤:
- * 1. 管理员登录后台
- * 2. 进入供应商商品管理页面
- * 3. 查看商品列表
- * 4. 搜索筛选商品
- * 5. 编辑商品信息
- * 6. 审核商品
- * 7. 查看商品分类
- *
- * 关键里程碑:
- * - [Milestone-1] 商品管理页面加载成功
- * - [Milestone-2] 商品列表加载正常
- * - [Milestone-3] 商品编辑成功
- * - [Milestone-4] 商品审核通过
- *
- * 运行:npx playwright test tests/e2e/vendor-product-manage.spec.js
- * ================================================================
- */
- const { test, expect } = require('@playwright/test');
- test.describe('【场景流程】供应商商品管理', () => {
- test.beforeEach(async ({ page }) => {
- // 管理员登录(admin 后台)
- await page.goto('http://cfc.iwintrue.com/admin/login');
- await page.waitForLoadState('networkidle');
- const adminPhone = '13701366188';
- const phoneInput = page.locator('input[placeholder="请输入手机号"]');
- await phoneInput.fill(adminPhone);
- await page.locator('.login-btn, button:has-text("登录")').click();
- await page.waitForTimeout(1500);
- // 验证登录成功
- try {
- await page.waitForSelector('.admin-tab, .admin-menu, .admin-layout', { timeout: 10000 });
- } catch (e) {
- if (await page.url().includes('/login')) {
- await page.goto('http://cfc.iwintrue.com/admin/supplier-products');
- await page.waitForLoadState('networkidle');
- }
- }
- });
- /**
- * 场景1:商品管理页面加载
- * 角色:管理员
- * 触发条件:进入供应商商品管理页面
- * 校验:页面加载成功,tab 切换到商品列表
- */
- test('[场景1] 商品管理页面加载 — 期望 tab 切换到商品列表', async ({ page }) => {
- await page.goto('http://cfc.iwintrue.com/admin/supplier-products');
- await page.waitForLoadState('networkidle');
- // 验证页面标题
- const title = page.locator('.el-card__header, .tab-header, h2:has-text("商品管理")');
- expect(await title.isVisible()).toBeTruthy();
- // 验证默认选中"商品列表" tab
- const listTab = page.locator('.nav-item.active, .el-tab-pane.is-active, text="商品列表"');
- expect(await listTab.isVisible()).toBeTruthy();
- });
- /**
- * 场景2:商品列表加载
- * 角色:管理员
- * 触发条件:进入商品管理页面
- * 校验:列表加载正常数据
- */
- test('[场景2] 商品列表加载 — 期望数据加载', async ({ page }) => {
- await page.goto('http://cfc.iwintrue.com/admin/supplier-products');
- await page.waitForLoadState('networkidle');
- // 验证列表加载
- const productRows = page.locator('.el-table__row, .product-row');
- const rowCount = await productRows.count();
- expect(rowCount).toBeGreaterThanOrEqual(0);
- // 验证列数
- if (rowCount > 0) {
- const firstRow = productRows.first();
- const cells = firstRow.locator('.el-table__cell');
- expect(await cells.count()).toBeGreaterThanOrEqual(6);
- }
- });
- /**
- * 场景3:搜索筛选商品
- * 角色:管理员
- * 触发条件:输入商品名称、供应商等筛选条件
- * 校验:列表刷新返回正常数据
- */
- test('[场景3] 搜索筛选商品 — 期望列表刷新', async ({ page }) => {
- await page.goto('http://cfc.iwintrue.com/admin/supplier-products');
- await page.waitForLoadState('networkidle');
- // 输入筛选条件
- const nameInput = page.locator('input[placeholder="商品名称"]');
- if (await nameInput.isVisible()) {
- await nameInput.fill('测试商品');
- }
- // 点击搜索按钮
- const searchBtn = page.locator('.search-btn, button:has-text("搜索")');
- await searchBtn.click();
- await page.waitForTimeout(1000);
- // 验证列表刷新
- const productRows = page.locator('.el-table__row');
- expect(await productRows.count()).toBeGreaterThanOrEqual(0);
- });
- /**
- * 场景4:查看商品详情
- * 角色:管理员
- * 触发条件:点击商品列表中的"详情"按钮
- * 校验:商品详情页面加载成功
- */
- test('[场景4] 查看商品详情 — 期望详情加载', async ({ page }) => {
- await page.goto('http://cfc.iwintrue.com/admin/supplier-products');
- await page.waitForLoadState('networkidle');
- // 查找第一个商品的详情按钮
- const detailBtn = page.locator('.el-table__row:first-child button:has-text("详情")');
- if (await detailBtn.isVisible()) {
- await detailBtn.click();
- await page.waitForTimeout(1000);
- // 验证详情加载
- const productInfo = page.locator('.product-info, .detail-card');
- expect(await productInfo.isVisible()).toBeTruthy();
- // 验证商品信息展示
- const productName = page.locator('.product-name, .title');
- expect(await productName.isVisible()).toBeTruthy();
- } else {
- // 无商品数据,跳过
- expect(true).toBeTruthy();
- }
- });
- /**
- * 场景5:编辑商品信息
- * 角色:管理员
- * 触发条件:点击商品列表中的"编辑"按钮
- * 校验:编辑表单加载成功
- */
- test('[场景5] 编辑商品信息 — 期望表单加载', async ({ page }) => {
- await page.goto('http://cfc.iwintrue.com/admin/supplier-products');
- await page.waitForLoadState('networkidle');
- // 查找第一个商品的编辑按钮
- const editBtn = page.locator('.el-table__row:first-child button:has-text("编辑")');
- if (await editBtn.isVisible()) {
- await editBtn.click();
- await page.waitForTimeout(1000);
- // 验证表单加载
- const formFields = page.locator('.el-form-item, .form-field');
- const fieldCount = await formFields.count();
- expect(fieldCount).toBeGreaterThanOrEqual(5);
- // 验证表单包含关键字段
- const nameInput = page.locator('input[placeholder*="名称"], input[name="name"]');
- expect(await nameInput.isVisible()).toBeTruthy();
- const priceInput = page.locator('input[placeholder*="价格"], input[name="price"]');
- expect(await priceInput.isVisible()).toBeTruthy();
- } else {
- // 无商品数据,跳过
- expect(true).toBeTruthy();
- }
- });
- /**
- * 场景6:审核商品
- * 角色:管理员
- * 触发条件:选择待审核商品,点击通过
- * 校验:审核成功,状态变为已上架
- */
- test('[场景6] 审核商品 — 期望通过成功', async ({ page }) => {
- await page.goto('http://cfc.iwintrue.com/admin/supplier-products');
- await page.waitForLoadState('networkidle');
- // 切换到审核 tab
- const reviewTab = page.locator('.nav-item:has-text("待审核"), .tab-item:has-text("待审核")');
- await reviewTab.click();
- await page.waitForTimeout(1000);
- // 查找待审核商品
- const pendingProducts = page.locator('.el-table__row:has-text("待审核")');
- const productCount = await pendingProducts.count();
- if (productCount > 0) {
- // 点击通过按钮
- const approveBtn = pendingProducts.first().locator('button:has-text("通过")');
- await approveBtn.click();
- await page.waitForTimeout(500);
- // 提交
- const submitBtn = page.locator('.el-dialog__footer button:has-text("确定"), button.el-button--primary');
- await submitBtn.click();
- await page.waitForTimeout(1000);
- // 验证提示
- const successTip = page.locator('.toast-success, text="审核通过"');
- expect(await successTip.isVisible().catch(() => false)).toBeTruthy();
- } else {
- // 无待审核商品,跳过
- expect(true).toBeTruthy();
- }
- });
- /**
- * 场景7:商品分类管理
- * 角色:管理员
- * 触发条件:进入商品分类页面
- * 校验:分类列表加载正常
- */
- test('[场景7] 商品分类管理 — 期望分类加载', async ({ page }) => {
- await page.goto('http://cfc.iwintrue.com/admin/category-manage');
- await page.waitForLoadState('networkidle');
- // 验证页面标题
- const title = page.locator('.el-card__header, .tab-header, h2:has-text("商品分类")');
- expect(await title.isVisible()).toBeTruthy();
- // 验证分类列表加载
- const categoryRows = page.locator('.el-table__row, .category-row');
- const rowCount = await categoryRows.count();
- expect(rowCount).toBeGreaterThanOrEqual(0);
- // 验证列数
- if (rowCount > 0) {
- const firstRow = categoryRows.first();
- const cells = firstRow.locator('.el-table__cell');
- expect(await cells.count()).toBeGreaterThanOrEqual(4);
- }
- });
- /**
- * 场景8:商品利润率配置
- * 角色:管理员
- * 触发条件:进入商品利润率页面
- * 校验:利润率配置加载正常
- */
- test('[场景8] 商品利润率配置 — 期望配置加载', async ({ page }) => {
- await page.goto('http://cfc.iwintrue.com/admin/product-profit-rate');
- await page.waitForLoadState('networkidle');
- // 验证页面标题
- const title = page.locator('.el-card__header, .tab-header, h2:has-text("利润率")');
- expect(await title.isVisible()).toBeTruthy();
- // 验证配置加载
- const profitRows = page.locator('.el-table__row, .profit-row');
- const rowCount = await profitRows.count();
- expect(rowCount).toBeGreaterThanOrEqual(0);
- // 验证列数
- if (rowCount > 0) {
- const firstRow = profitRows.first();
- const cells = firstRow.locator('.el-table__cell');
- expect(await cells.count()).toBeGreaterThanOrEqual(5);
- }
- });
- });
|