feat(erp-frontend-vue): add Playwright E2E tests and update layout
Add Playwright configuration and E2E specs for key production, purchasing, and warehouse flows, and update layout/login to align with the new testing setup. Made-with: Cursor
This commit is contained in:
24
erp-frontend-vue/tests/production-need-report.spec.ts
Normal file
24
erp-frontend-vue/tests/production-need-report.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { login, clickSubMenu, clickMenuItem, expectBasicList } from './utils/erpTestUtils'
|
||||
|
||||
test.describe('采购计划需求表页面', () => {
|
||||
test('报表查询基础交互', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '生产计划')
|
||||
await clickMenuItem(page, '/production/report/need')
|
||||
await expect(page).toHaveURL(/\/production\/report\/need/)
|
||||
await expectBasicList(page)
|
||||
|
||||
const dateRange = page.getByPlaceholder(/开始日期|结束日期|选择日期范围/).first().catch(() => null)
|
||||
if (dateRange) {
|
||||
await dateRange.click()
|
||||
await page.getByRole('button', { name: /今/ }).first().click().catch(() => {})
|
||||
await page.getByRole('button', { name: /确 定|确定/ }).first().click().catch(() => {})
|
||||
}
|
||||
|
||||
await page.getByRole('button', { name: /搜索|查询/ }).click()
|
||||
await expect(page.locator('.el-table').first()).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
87
erp-frontend-vue/tests/production-plan-order.spec.ts
Normal file
87
erp-frontend-vue/tests/production-plan-order.spec.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { login, clickSubMenu, clickMenuItem, expectBasicList } from './utils/erpTestUtils'
|
||||
|
||||
test.describe('生产计划单页面', () => {
|
||||
test('明细视图与单据视图切换 + 查询', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '生产计划')
|
||||
await clickMenuItem(page, '/production/plan-order')
|
||||
await expect(page).toHaveURL(/\/production\/plan-order/)
|
||||
await expectBasicList(page)
|
||||
|
||||
// 明细视图:包含销售订单号/物料编码等字段
|
||||
await expect(page.getByText('销售订单号')).toBeVisible()
|
||||
await expect(page.getByText('物料编码')).toBeVisible()
|
||||
|
||||
// 切换到单据视图
|
||||
await page.getByRole('button', { name: '单据' }).click()
|
||||
await expect(page.getByText('业务状态')).toBeVisible()
|
||||
|
||||
// 在单据视图中按单据编码+状态查询
|
||||
const codeInput = page.getByLabel('单据编码').locator('input')
|
||||
await codeInput.fill('TEST')
|
||||
await page.getByRole('button', { name: /搜索/ }).click()
|
||||
})
|
||||
|
||||
test('新增生产计划单基础表单交互', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '生产计划')
|
||||
await clickMenuItem(page, '/production/plan-order')
|
||||
|
||||
// 打开新增页
|
||||
await page.getByRole('button', { name: /新增/ }).click()
|
||||
await expect(page).toHaveURL(/\/production\/plan-order\/(new|edit)/)
|
||||
await expect(page.locator('.el-form').first()).toBeVisible()
|
||||
|
||||
// 表头基本字段存在(生产计划单文档:计划单号/计划日期/业务类型/工作类型等)
|
||||
await expect(page.getByText(/单据编码|计划单号/)).toBeVisible()
|
||||
await expect(page.getByText(/单据日期|计划日期/)).toBeVisible()
|
||||
|
||||
// 引入订单弹窗:根据 PRD,通过「引入」按钮选择销售订单/备货订单
|
||||
const importBtn = page.getByRole('button', { name: /引入/ }).first()
|
||||
if (await importBtn.isVisible().catch(() => false)) {
|
||||
await importBtn.click()
|
||||
await expect(page.getByText('订单信息')).toBeVisible()
|
||||
await expect(page.locator('.el-dialog').locator('.el-table').first()).toBeVisible()
|
||||
await page.getByRole('button', { name: /关 闭|关闭|取 消/ }).click()
|
||||
}
|
||||
|
||||
// 订单 BOM 选择弹窗
|
||||
const bomSelectBtn = page.getByRole('button', { name: /选择BOM|选择/ }).first().catch(() => null)
|
||||
if (bomSelectBtn) {
|
||||
await bomSelectBtn
|
||||
await expect(page.getByText(/选择EBOM|选择BOM/)).toBeVisible()
|
||||
await page.getByRole('button', { name: /关 闭|关闭|取 消/ }).click()
|
||||
}
|
||||
})
|
||||
|
||||
test('物料清单(BOM运算结果)区域交互', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '生产计划')
|
||||
await clickMenuItem(page, '/production/plan-order')
|
||||
|
||||
// 打开一个已存在的计划单(若有)
|
||||
const firstLink = page.locator('.el-table').first().getByRole('link').first()
|
||||
if (!(await firstLink.isVisible().catch(() => false))) test.skip()
|
||||
|
||||
await firstLink.click()
|
||||
await expect(page.locator('.section-title', { hasText: '物料清单' })).toBeVisible()
|
||||
|
||||
// BOM 运算按钮存在且可点(如果该单据允许)
|
||||
const bomBtn = page.getByRole('button', { name: 'BOM运算' }).first()
|
||||
if (await bomBtn.isVisible().catch(() => false)) {
|
||||
await bomBtn.click()
|
||||
// 可能出现 loading 或消息提示,这里只校验不会报错
|
||||
}
|
||||
|
||||
// 物料清单表格中的下发车间、供应方式、齐套检查/补料列存在
|
||||
const mbomTable = page.locator('.material-section').nth(0).locator('.el-table').first()
|
||||
await expect(mbomTable).toBeVisible()
|
||||
await expect(page.getByText(/供应方式/)).toBeVisible()
|
||||
await expect(page.getByText(/下发车间/)).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
32
erp-frontend-vue/tests/production-purchase-plan.spec.ts
Normal file
32
erp-frontend-vue/tests/production-purchase-plan.spec.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { login, clickSubMenu, clickMenuItem, expectBasicList } from './utils/erpTestUtils'
|
||||
|
||||
test.describe('采购计划单页面', () => {
|
||||
test('列表搜索 & 新增采购计划单 & 导出', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '生产计划')
|
||||
await clickMenuItem(page, '/production/purchase-plan')
|
||||
await expect(page).toHaveURL(/\/production\/purchase-plan/)
|
||||
await expectBasicList(page)
|
||||
|
||||
const planCodeInput = page.getByPlaceholder(/计划单号|采购计划/).first().catch(() => null)
|
||||
if (planCodeInput) {
|
||||
await planCodeInput.fill('TEST')
|
||||
await page.getByRole('button', { name: /搜索|查询/ }).click()
|
||||
}
|
||||
|
||||
const addBtn = page.getByRole('button', { name: /新增|新建/ }).first()
|
||||
await addBtn.click()
|
||||
await expect(page).toHaveURL(/\/production\/purchase-plan\/(new|edit|form)/)
|
||||
await expect(page.locator('.el-form').first()).toBeVisible()
|
||||
await page.goBack().catch(() => {})
|
||||
|
||||
const exportBtn = page.getByRole('button', { name: /导出/ }).first()
|
||||
if (await exportBtn.isVisible().catch(() => false)) {
|
||||
await exportBtn.click()
|
||||
// 此处主要校验点击不报错
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
52
erp-frontend-vue/tests/production-work-order.spec.ts
Normal file
52
erp-frontend-vue/tests/production-work-order.spec.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { login, clickSubMenu, clickMenuItem, expectBasicList } from './utils/erpTestUtils'
|
||||
|
||||
test.describe('生产订单页面', () => {
|
||||
test('列表搜索与基本操作按钮存在', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '生产管理')
|
||||
await clickMenuItem(page, '/production/work-order')
|
||||
await expect(page).toHaveURL(/\/production\/work-order/)
|
||||
await expectBasicList(page)
|
||||
|
||||
// 搜索区字段
|
||||
await expect(page.getByLabel('工单编码')).toBeVisible()
|
||||
await expect(page.getByLabel('计划单号')).toBeVisible()
|
||||
await page.getByRole('button', { name: /搜索/ }).click()
|
||||
await page.getByRole('button', { name: '重置' }).click()
|
||||
|
||||
// 工具栏按钮:新增/修改/删除/导出
|
||||
await expect(page.getByRole('button', { name: /新增/ })).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: /修改/ })).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: /删除/ })).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: /导出/ })).toBeVisible()
|
||||
})
|
||||
|
||||
test('查看工单详情与状态相关操作按钮', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '生产管理')
|
||||
await clickMenuItem(page, '/production/work-order')
|
||||
|
||||
const firstRow = page.locator('.el-table__row').first()
|
||||
if (!(await firstRow.isVisible().catch(() => false))) test.skip()
|
||||
|
||||
// 查看按钮
|
||||
const viewBtn = firstRow.getByRole('button', { name: '查看' }).first()
|
||||
await viewBtn.click()
|
||||
await expect(page.locator('.el-dialog, .el-drawer, .page-container').first()).toBeVisible()
|
||||
await page.goBack().catch(() => {})
|
||||
|
||||
// 根据不同状态可能出现:审核、一键领料、完工、取消等按钮
|
||||
// 这里只做存在性和可点击性检查(不强制业务成功)
|
||||
const quickIssueBtn = firstRow.getByRole('button', { name: /一键领料/ }).first()
|
||||
if (await quickIssueBtn.isVisible().catch(() => false)) {
|
||||
await quickIssueBtn.click()
|
||||
// 可能弹确认框,选择取消
|
||||
const confirm = page.getByRole('button', { name: /取 消|取消/ }).first()
|
||||
await confirm.click().catch(() => {})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
30
erp-frontend-vue/tests/purchasing-checkin.spec.ts
Normal file
30
erp-frontend-vue/tests/purchasing-checkin.spec.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { login, clickSubMenu, clickMenuItem, expectBasicList } from './utils/erpTestUtils'
|
||||
|
||||
test.describe('采购到货单页面', () => {
|
||||
test('列表页加载 & 查询 & 查看详情', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '采购管理')
|
||||
await clickMenuItem(page, '/purchasing/checkin')
|
||||
await expect(page).toHaveURL(/\/purchasing\/checkin/)
|
||||
await expectBasicList(page)
|
||||
|
||||
const supplierInput = page.getByPlaceholder(/供应商/).first().catch(() => null)
|
||||
if (supplierInput) {
|
||||
await supplierInput.fill('测试供应商')
|
||||
await page.getByRole('button', { name: /搜索|查询/ }).click()
|
||||
}
|
||||
|
||||
const firstRow = page.locator('.el-table__row').first()
|
||||
if (await firstRow.isVisible().catch(() => false)) {
|
||||
const viewBtn = firstRow.getByRole('button', { name: /查看/ }).first()
|
||||
if (await viewBtn.isVisible().catch(() => false)) {
|
||||
await viewBtn.click()
|
||||
await expect(page.locator('.el-dialog__body')).toBeVisible()
|
||||
await page.getByRole('button', { name: /关 闭|关闭|取 消/ }).click().catch(() => {})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
28
erp-frontend-vue/tests/purchasing-order.spec.ts
Normal file
28
erp-frontend-vue/tests/purchasing-order.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { login, clickSubMenu, clickMenuItem, expectBasicList } from './utils/erpTestUtils'
|
||||
|
||||
test.describe('采购订单页面', () => {
|
||||
test('列表搜索与新增采购订单表单', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '采购管理')
|
||||
await clickMenuItem(page, '/purchasing/order')
|
||||
await expect(page).toHaveURL(/\/purchasing\/order/)
|
||||
await expectBasicList(page)
|
||||
|
||||
// 按订单编号/供应商搜索
|
||||
const codeInput = page.getByPlaceholder(/订单编号|采购订单/).first().catch(() => null)
|
||||
if (codeInput) {
|
||||
await codeInput.fill('TEST')
|
||||
}
|
||||
await page.getByRole('button', { name: /搜索|查询/ }).click()
|
||||
|
||||
// 新增采购订单
|
||||
const addBtn = page.getByRole('button', { name: /新增|新建/ }).first()
|
||||
await addBtn.click()
|
||||
await expect(page).toHaveURL(/\/purchasing\/order\/(new|edit|form)/)
|
||||
await expect(page.locator('.el-form').first()).toBeVisible()
|
||||
await expect(page.locator('.el-table').first()).toBeVisible() // 明细
|
||||
})
|
||||
})
|
||||
|
||||
49
erp-frontend-vue/tests/rd-ebom.spec.ts
Normal file
49
erp-frontend-vue/tests/rd-ebom.spec.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { login, clickSubMenu, clickMenuItem, expectBasicList } from './utils/erpTestUtils'
|
||||
|
||||
test.describe('产品 BOM(EBOM)页面', () => {
|
||||
test('明细/单据视图切换与搜索', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '研发管理')
|
||||
await clickMenuItem(page, '/rd/ebom')
|
||||
await expect(page).toHaveURL(/\/rd\/ebom/)
|
||||
await expectBasicList(page)
|
||||
|
||||
// 明细视图:物料分类筛选存在
|
||||
await expect(page.getByText('物料分类')).toBeVisible()
|
||||
|
||||
// 切换到单据视图
|
||||
await page.getByRole('button', { name: '单据' }).click()
|
||||
await expect(page.getByText('业务状态')).toBeVisible()
|
||||
|
||||
// 单据视图按单据状态/业务状态查询
|
||||
const statusSelect = page.getByLabel('单据状态')
|
||||
await statusSelect.click()
|
||||
await page.getByRole('option').first().click()
|
||||
await page.getByRole('button', { name: /搜索/ }).click()
|
||||
})
|
||||
|
||||
test('新增 BOM 表单基本交互', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '研发管理')
|
||||
await clickMenuItem(page, '/rd/ebom')
|
||||
|
||||
await page.getByRole('button', { name: /新增/ }).click()
|
||||
await expect(page).toHaveURL(/\/ebom\/(new|edit)/)
|
||||
await expect(page.locator('.el-form').first()).toBeVisible()
|
||||
|
||||
// 母件物料选择弹窗
|
||||
const itemSelectBtn = page.getByRole('button', { name: /选择物料|选择/ }).first().catch(() => null)
|
||||
if (itemSelectBtn) {
|
||||
await itemSelectBtn
|
||||
await expect(page.locator('.el-dialog').filter({ hasText: /选择物料/ })).toBeVisible()
|
||||
await page.getByRole('button', { name: /关 闭|关闭|取 消/ }).click().catch(() => {})
|
||||
}
|
||||
|
||||
// 明细表格存在
|
||||
await expect(page.locator('.el-table').first()).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
33
erp-frontend-vue/tests/utils/erpTestUtils.ts
Normal file
33
erp-frontend-vue/tests/utils/erpTestUtils.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { expect, Page } from '@playwright/test'
|
||||
|
||||
export const USERNAME = process.env.ERP_USER || 'admin'
|
||||
export const PASSWORD = process.env.ERP_PASS || 'admin123'
|
||||
|
||||
export async function login(page: Page) {
|
||||
await page.goto('/login')
|
||||
|
||||
await page.getByPlaceholder(/用户名|账号/).fill(USERNAME)
|
||||
await page.getByPlaceholder(/密码/).fill(PASSWORD)
|
||||
|
||||
const codeInput = page.getByPlaceholder(/验证码/).first()
|
||||
if (await codeInput.isVisible().catch(() => false)) {
|
||||
await codeInput.fill('0000')
|
||||
}
|
||||
|
||||
await page.getByRole('button', { name: /登录|登 录/ }).click()
|
||||
await expect(page).toHaveURL(/dashboard/)
|
||||
}
|
||||
|
||||
export async function clickSubMenu(page: Page, title: string) {
|
||||
await page.click(`.el-sub-menu__title:has-text("${title}")`)
|
||||
}
|
||||
|
||||
export async function clickMenuItem(page: Page, path: string) {
|
||||
await page.click(`.el-menu-item[index="${path}"]`)
|
||||
}
|
||||
|
||||
export async function expectBasicList(page: Page) {
|
||||
await expect(page.locator('.el-form').first()).toBeVisible()
|
||||
await expect(page.locator('.el-table').first()).toBeVisible()
|
||||
}
|
||||
|
||||
28
erp-frontend-vue/tests/warehouse-issue.spec.ts
Normal file
28
erp-frontend-vue/tests/warehouse-issue.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { login, clickSubMenu, clickMenuItem, expectBasicList } from './utils/erpTestUtils'
|
||||
|
||||
test.describe('生产领料单页面', () => {
|
||||
test('列表搜索 & 打开新建领料单', async ({ page }) => {
|
||||
await login(page)
|
||||
|
||||
await clickSubMenu(page, '生产管理')
|
||||
await clickMenuItem(page, '/warehouse/issue')
|
||||
await expect(page).toHaveURL(/\/warehouse\/issue/)
|
||||
await expectBasicList(page)
|
||||
|
||||
const issueCodeInput = page.getByPlaceholder(/领料单号|单据编号/).first().catch(() => null)
|
||||
if (issueCodeInput) {
|
||||
await issueCodeInput.fill('TEST')
|
||||
await page.getByRole('button', { name: /搜索|查询/ }).click()
|
||||
}
|
||||
|
||||
const addBtn = page.getByRole('button', { name: /新建|新增/ }).first()
|
||||
if (await addBtn.isVisible().catch(() => false)) {
|
||||
await addBtn.click()
|
||||
await expect(page).toHaveURL(/\/warehouse\/issue\/(new|edit|form)/)
|
||||
await expect(page.locator('.el-form').first()).toBeVisible()
|
||||
await expect(page.locator('.el-table').first()).toBeVisible()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user