taskCenter.e2e.js
8.36 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
/**
* 任务中心 E2E 测试
*
* 测试场景:
* 1. 导航到任务中心页面
* 2. 验证任务列表显示
* 3. 使用筛选条件搜索任务
* 4. 查看任务详情
* 5. 验证排序功能
* 6. 验证分页功能
* 7. 验证任务汇总统计
*
* 登录策略:共享 context,beforeAll 登录一次,所有 test 复用同一个 page
* (应用登录态依赖 Vuex 内存,无法通过 storageState 跨 context 保持)
*/
import { expect, test } from "@playwright/test";
import { createLoggedInPage, getBaseUrl } from "./helpers/auth.js";
const BASE_URL = getBaseUrl();
test.describe("任务中心 (Task Center)", () => {
let sharedPage;
// 全局前置:只运行一次,登录后共享 page(Vuex 内存态)
test.beforeAll(async ({ browser }) => {
sharedPage = await createLoggedInPage(browser);
console.log("登录完成");
});
// 全部测试结束后清理
test.afterAll(async () => {
await sharedPage.context().close();
});
test("应该能够访问任务中心页面", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
await expect(sharedPage.locator(".table-title-wrapper .title")).toContainText("任务列表");
});
test("应该显示任务汇总统计", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
const summaryTags = sharedPage.locator(".table-sum-wrapper .el-tag");
await expect(summaryTags).toHaveCount(4);
await expect(summaryTags.nth(0)).toContainText("总任务数");
await expect(summaryTags.nth(1)).toContainText("未完成");
await expect(summaryTags.nth(2)).toContainText("已完成");
await expect(summaryTags.nth(3)).toContainText("已逾期");
});
test("应该能够使用筛选条件搜索 - 任务编号", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
const searchForm = sharedPage.locator(".d2-search");
await expect(searchForm).toBeVisible();
const taskNoInput = sharedPage.locator("input[placeholder*=\"任务编号\"], input[name*=\"taskNo\"]");
if (await taskNoInput.count() > 0) {
await taskNoInput.fill("T2026");
}
const searchButton = sharedPage.locator("button:has-text(\"查询\")");
await expect(searchButton).toBeVisible();
await searchButton.click();
await sharedPage.waitForLoadState("networkidle");
});
test("应该能够使用筛选条件搜索 - 任务标题", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
const titleInput = sharedPage.locator("input[placeholder*=\"任务标题\"], input[name*=\"title\"]");
if (await titleInput.count() > 0) {
await titleInput.fill("测试任务");
}
const searchButton = sharedPage.locator("button:has-text(\"查询\")");
await searchButton.click();
await sharedPage.waitForLoadState("networkidle");
});
test("应该能够使用筛选条件搜索 - 优先级", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
const prioritySelect = sharedPage.locator("select[name*=\"priorities\"], .el-select:has-text(\"优先级\")");
if (await prioritySelect.count() > 0) {
await prioritySelect.click();
const urgentOption = sharedPage.locator(".el-select-dropdown__item:has-text(\"紧急\")");
if (await urgentOption.count() > 0) {
await urgentOption.click();
}
}
const searchButton = sharedPage.locator("button:has-text(\"查询\")");
await searchButton.click();
await sharedPage.waitForLoadState("networkidle");
});
test("应该能够使用筛选条件搜索 - 完成状态", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
const statusSelect = sharedPage.locator("select[name*=\"status\"], .el-select:has-text(\"完成状态\")");
if (await statusSelect.count() > 0) {
await statusSelect.click();
const finishedOption = sharedPage.locator(".el-select-dropdown__item:has-text(\"已完成\")");
if (await finishedOption.count() > 0) {
await finishedOption.click();
}
}
const searchButton = sharedPage.locator("button:has-text(\"查询\")");
await searchButton.click();
await sharedPage.waitForLoadState("networkidle");
});
test("应该能够使用筛选条件搜索 - 是否逾期", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
const overdueSelect = sharedPage.locator("select[name*=\"overdueFlag\"], .el-select:has-text(\"是否逾期\")");
if (await overdueSelect.count() > 0) {
await overdueSelect.click();
const overdueOption = sharedPage.locator(".el-select-dropdown__item:has-text(\"逾期\")");
if (await overdueOption.count() > 0) {
await overdueOption.click();
}
}
const searchButton = sharedPage.locator("button:has-text(\"查询\")");
await searchButton.click();
await sharedPage.waitForLoadState("networkidle");
});
test("应该能够重置搜索条件", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
const resetButton = sharedPage.locator("button:has-text(\"重置\")");
await expect(resetButton).toBeVisible();
await resetButton.click();
await sharedPage.waitForLoadState("networkidle");
});
test("应该能够切换排序方式", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
const sortDropdown = sharedPage.locator(".sort-wrapper .el-dropdown-link");
await expect(sortDropdown).toBeVisible();
await sortDropdown.click();
const sortOptions = sharedPage.locator(".el-dropdown-menu__item");
await expect(sortOptions).toHaveCount(2);
await expect(sortOptions.nth(0)).toContainText("按创建时间");
await expect(sortOptions.nth(1)).toContainText("按截止时间");
await sortOptions.nth(1).click();
await sharedPage.waitForLoadState("networkidle");
await expect(sortDropdown).toContainText("按截止时间");
});
test("应该能够查看任务详情", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
const table = sharedPage.locator(".d2-table");
await expect(table).toBeVisible();
const firstRow = sharedPage.locator(".el-table__body tr").first();
await expect(firstRow).toBeVisible();
const taskNoCell = firstRow.locator("td").nth(1);
const taskNo = await taskNoCell.textContent();
const viewButton = firstRow.locator("button:has-text(\"查看\"), .auth-button");
if (await viewButton.count() > 0) {
await viewButton.click();
await sharedPage.waitForLoadState("networkidle");
await expect(sharedPage).toHaveURL(/.*task-center\/detail.*taskId=/);
const detailTitle = sharedPage.locator(".title-wrapper .title");
await expect(detailTitle).toBeVisible();
}
});
test("详情页应该显示任务信息", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center/detail?taskId=TASK001`);
await sharedPage.waitForLoadState("networkidle");
const descriptionWrapper = sharedPage.locator(".description-wrapper");
await expect(descriptionWrapper).toBeVisible();
const backButton = sharedPage.locator(".back-btn, button:has-text('Back'), .VenusBackButton");
if (await backButton.count() > 0) {
await expect(backButton.first()).toBeVisible();
}
});
test("详情页应该能够返回", async () => {
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center/detail?taskId=TASK001`);
await sharedPage.waitForLoadState("networkidle");
const backButton = sharedPage.locator(".back-btn, .VenusBackButton");
if (await backButton.count() > 0) {
await backButton.first().click();
await sharedPage.waitForLoadState("networkidle");
await expect(sharedPage).toHaveURL(/.*resident-manage\/task-center.*/);
}
});
test("移动端视口适配", async () => {
await sharedPage.setViewportSize({ width: 375, height: 667 });
await sharedPage.goto(`${BASE_URL}/#/resident-manage/task-center`);
await sharedPage.waitForLoadState("networkidle");
await expect(sharedPage.locator(".table-title-wrapper .title")).toBeVisible();
});
});