account.spec.ts
5.1 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
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();
});
});
});