Commit 486d0cf66bf85c3549c176a7afaddd03bd3a95d5
1 parent
0247a9d4
合并分支
Showing
1 changed file
with
104 additions
and
0 deletions
tests/account.spec.ts
0 → 100644
| 1 | +// import { test, expect } from '@playwright/test'; | ||
| 2 | +// import * as allure from 'allure-js-commons'; | ||
| 3 | + | ||
| 4 | +// /** | ||
| 5 | +// * 账目管理测试 | ||
| 6 | +// */ | ||
| 7 | +// test.describe('账目管理', () => { | ||
| 8 | +// // 使用已保存的认证状态 | ||
| 9 | +// test.use({ storageState: 'auth.json' }); | ||
| 10 | + | ||
| 11 | +// // 强制测试串行执行 | ||
| 12 | +// test.describe.configure({ mode: 'serial' }); | ||
| 13 | + | ||
| 14 | +// /** | ||
| 15 | +// * 生成随机账目名称(三个字+"费",带时间戳后缀防止重复) | ||
| 16 | +// */ | ||
| 17 | +// function generateAccountName(): string { | ||
| 18 | +// const prefixes = ['管理', '维护', '看管', '保管', '仓储', '代理', '服务', '咨询', '技术', '运营']; | ||
| 19 | +// const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; | ||
| 20 | +// const timestamp = Date.now().toString().slice(-4); | ||
| 21 | +// return `${prefix}费${timestamp}`; | ||
| 22 | +// } | ||
| 23 | + | ||
| 24 | +// /** | ||
| 25 | +// * 生成随机收支类型 | ||
| 26 | +// */ | ||
| 27 | +// function generateIncomeType(): '收入' | '支出' { | ||
| 28 | +// return Math.random() > 0.5 ? '收入' : '支出'; | ||
| 29 | +// } | ||
| 30 | + | ||
| 31 | +// /** | ||
| 32 | +// * 生成包含"自动化"的备注 | ||
| 33 | +// */ | ||
| 34 | +// function generateRemark(): string { | ||
| 35 | +// const timestamp = Date.now().toString().slice(-6); | ||
| 36 | +// return `自动化测试备注${timestamp}`; | ||
| 37 | +// } | ||
| 38 | + | ||
| 39 | +// test('新增账目', async ({ page }, testInfo) => { | ||
| 40 | +// // 添加allure元素 | ||
| 41 | +// await allure.epic('账目管理'); | ||
| 42 | +// await allure.feature('账目信息'); | ||
| 43 | +// await allure.story('新增账目'); | ||
| 44 | + | ||
| 45 | +// // 生成随机账目数据 | ||
| 46 | +// const accountName = generateAccountName(); | ||
| 47 | +// const incomeType = generateIncomeType(); | ||
| 48 | +// const remark = generateRemark(); | ||
| 49 | + | ||
| 50 | +// console.log('账目名称:', accountName); | ||
| 51 | +// console.log('收支类型:', incomeType); | ||
| 52 | +// console.log('备注:', remark); | ||
| 53 | + | ||
| 54 | +// // 步骤1:进入账目管理页面 | ||
| 55 | +// await allure.step('进入账目管理页面', async () => { | ||
| 56 | +// await page.goto('/'); | ||
| 57 | +// await page.waitForLoadState('networkidle', { timeout: 30000 }); | ||
| 58 | +// await page.getByText('更多 >').click(); | ||
| 59 | +// await page.waitForTimeout(500); | ||
| 60 | +// await page.getByText('账目管理').first().click(); | ||
| 61 | +// await page.waitForLoadState('networkidle', { timeout: 30000 }); | ||
| 62 | +// }); | ||
| 63 | + | ||
| 64 | +// // 步骤2:点击新增按钮 | ||
| 65 | +// await allure.step('点击新增按钮', async () => { | ||
| 66 | +// await page.getByText('新增', { exact: true }).click(); | ||
| 67 | +// await page.waitForTimeout(500); | ||
| 68 | +// }); | ||
| 69 | + | ||
| 70 | +// // 步骤3:填写账目表单 | ||
| 71 | +// await allure.step('填写账目表单', async () => { | ||
| 72 | +// // 填写账目名称 | ||
| 73 | +// await page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').click(); | ||
| 74 | +// await page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').fill(accountName); | ||
| 75 | + | ||
| 76 | +// // 选择收支类型 | ||
| 77 | +// if (incomeType === '支出') { | ||
| 78 | +// await page.locator('.nut-radio-group > uni-view:nth-child(2) > .nut-icon').click(); | ||
| 79 | +// } | ||
| 80 | +// // 收入是默认选项,无需选择 | ||
| 81 | + | ||
| 82 | +// // 填写备注 | ||
| 83 | +// await page.locator('uni-scroll-view').filter({ hasText: '账目名称*科目名称收支类别 收入 支出 启用状态备注请输入' }).locator('textarea').click(); | ||
| 84 | +// await page.locator('uni-scroll-view').filter({ hasText: '账目名称*科目名称收支类别 收入 支出 启用状态备注请输入' }).locator('textarea').fill(remark); | ||
| 85 | +// }); | ||
| 86 | + | ||
| 87 | +// // 步骤4:保存账目 | ||
| 88 | +// await allure.step('保存账目', async () => { | ||
| 89 | +// await page.getByText('保存').click(); | ||
| 90 | +// await page.waitForTimeout(1000); | ||
| 91 | +// }); | ||
| 92 | + | ||
| 93 | +// // 步骤5:验证账目创建成功 | ||
| 94 | +// await allure.step('验证账目创建成功', async () => { | ||
| 95 | +// await page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').click(); | ||
| 96 | +// await page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').fill(accountName); | ||
| 97 | +// await page.waitForTimeout(1000); | ||
| 98 | + | ||
| 99 | +// // 验证账目名称出现在列表中 | ||
| 100 | +// const accountVisible = await page.locator(`uni-view:has-text("${accountName}")`).isVisible().catch(() => false); | ||
| 101 | +// expect(accountVisible).toBeTruthy(); | ||
| 102 | +// }); | ||
| 103 | +// }); | ||
| 104 | +// }); |