account.spec.ts
9.26 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<<<<<<< HEAD
// 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();
// });
// });
// });
=======
import { test, expect } from '@playwright/test';
import * as allure from 'allure-js-commons';
import { AccountPage } from '../pages/accountPage';
/**
* 账目管理测试
*/
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) => {
const accountPage = new AccountPage(page);
// 添加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 accountPage.openAccountManagement();
});
// 步骤2:点击新增按钮
await allure.step('点击新增按钮', async () => {
await accountPage.clickAddButton();
});
// 步骤3:填写账目表单
await allure.step('填写账目表单', async () => {
await accountPage.fillAccountName(accountName);
await accountPage.selectIncomeType(incomeType);
await accountPage.fillRemark(remark);
});
// 步骤4:保存账目
await allure.step('保存账目', async () => {
await accountPage.saveAccount();
});
// 步骤5:验证账目创建成功
await allure.step('验证账目创建成功', async () => {
await accountPage.searchAccount(accountName);
const isCreated = await accountPage.verifyAccountExists(accountName);
expect(isCreated).toBeTruthy();
});
});
test('删除账目', async ({ page }, testInfo) => {
const accountPage = new AccountPage(page);
// 添加allure元素
await allure.epic('账目管理');
await allure.feature('账目信息');
await allure.story('删除账目');
// 生成随机账目数据
const accountName = generateAccountName();
console.log('待删除账目名称:', accountName);
// 步骤1:新增账目
await allure.step('新增账目', async () => {
await accountPage.openAccountManagement();
await accountPage.clickAddButton();
await accountPage.fillAccountName(accountName);
await accountPage.saveAccount();
});
// 步骤2:删除账目
await allure.step('删除账目', async () => {
await accountPage.deleteAccount(accountName);
});
// 步骤3:验证账目删除成功
await allure.step('验证账目删除成功', async () => {
const isDeleted = await accountPage.verifyAccountDeleted(accountName);
expect(isDeleted).toBeTruthy();
});
});
test('修改账目', async ({ page }, testInfo) => {
const accountPage = new AccountPage(page);
// 添加allure元素
await allure.epic('账目管理');
await allure.feature('账目信息');
await allure.story('修改账目');
// 生成随机账目数据
const originalName = generateAccountName();
const newName = generateAccountName();
const incomeType = generateIncomeType();
const remark = generateRemark();
console.log('原账目名称:', originalName);
console.log('新账目名称:', newName);
console.log('收支类型:', incomeType);
console.log('备注:', remark);
// 步骤1:新增账目
await allure.step('新增账目', async () => {
await accountPage.openAccountManagement();
await accountPage.clickAddButton();
await accountPage.fillAccountName(originalName);
await accountPage.saveAccount();
});
// 步骤2:修改账目
await allure.step('修改账目', async () => {
await accountPage.updateAccount(originalName, newName, incomeType, remark);
});
// 步骤3:验证账目修改成功
await allure.step('验证账目修改成功', async () => {
// 清除搜索框
await accountPage.clearSearchBox();
// 搜索修改后的账目名称
await accountPage.searchAccount(newName);
const isExists = await accountPage.verifyAccountExists(newName);
expect(isExists).toBeTruthy();
});
});
});
>>>>>>> xfbhzxt