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