employeePage.ts
7.24 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
import { Page, Locator, expect } from '@playwright/test';
import { BasePage } from './basePage';
/**
* 员工管理页面类
* 处理员工管理相关操作
*/
export class EmployeePage extends BasePage {
// 导航定位器
readonly employeeMenu: Locator;
// 操作按钮
readonly newEmployeeButton: Locator;
readonly manualAddButton: Locator;
readonly confirmButton: Locator;
// 表单字段
readonly employeeNameInput: Locator;
readonly phoneInput: Locator;
readonly remarkInput: Locator;
readonly positionInput: Locator;
// 岗位列表
readonly positionOption: Locator;
constructor(page: Page) {
super(page);
this.employeeMenu = page.getByText('员工管理').first();
this.newEmployeeButton = page.getByText('新建员工');
this.manualAddButton = page.getByText('手动添加');
this.confirmButton = page.getByText('确定');
this.employeeNameInput = page.locator('uni-input').filter({ hasText: '请输入员工姓名' }).getByRole('textbox');
this.phoneInput = page.getByRole('spinbutton');
this.remarkInput = page.locator('uni-input').filter({ hasText: '请输入备注信息' }).getByRole('textbox');
this.positionInput = page.locator('.nut-cell__link').first();
this.positionOption = page.locator('uni-view').filter({ hasText: /^岗位名称$/ }).first();
}
/**
* 进入员工管理页面
*/
async openEmployeeManagement(): Promise<void> {
await this.navigate('/');
await this.employeeMenu.click();
await this.page.waitForLoadState('networkidle', { timeout: 30000 });
}
/**
* 点击新建员工按钮
*/
async clickNewEmployee(): Promise<void> {
await this.newEmployeeButton.click();
await this.page.waitForTimeout(500);
}
/**
* 点击手动添加
*/
async clickManualAdd(): Promise<void> {
await this.manualAddButton.click();
await this.page.waitForTimeout(500);
}
/**
* 填写员工姓名
* @param name 员工姓名
*/
async fillEmployeeName(name: string): Promise<void> {
await this.employeeNameInput.click();
await this.employeeNameInput.fill(name);
}
/**
* 填写联系电话
* @param phone 联系电话
*/
async fillPhone(phone: string): Promise<void> {
await this.phoneInput.click();
await this.phoneInput.fill(phone);
}
/**
* 填写备注
* @param remark 备注信息
*/
async fillRemark(remark: string): Promise<void> {
await this.remarkInput.click();
await this.remarkInput.fill(remark);
}
/**
* 选择岗位
* @param position 岗位名称(可选,不传则随机选择)
*/
async selectPosition(position?: string): Promise<void> {
// 点击岗位名称输入框打开下拉列表
await this.page.locator('uni-view:nth-child(6) > .nut-cell__value > .nut-form-item__body__slots > .nut-input > .nut-input__value > .nut-input__mask').click();
await this.page.waitForTimeout(500);
if (position) {
// 选择指定岗位
await this.page.locator('uni-view').filter({ hasText: position }).first().click();
} else {
// 随机选择岗位 - 获取所有岗位选项并随机选择一个
const options = this.page.locator('uni-view').filter({ hasText: /^销售员$|^仓库管理员$/ });
const count = await options.count();
if (count > 0) {
const randomIndex = Math.floor(Math.random() * count);
await options.nth(randomIndex).click();
}
}
await this.page.waitForTimeout(300);
}
/**
* 点击确定按钮
*/
async clickConfirm(): Promise<void> {
await this.confirmButton.click();
await this.page.waitForTimeout(1000);
}
/**
* 搜索员工
* @param name 员工姓名
*/
async searchEmployee(name: string): Promise<void> {
await this.page.getByRole('textbox').click();
await this.page.getByRole('textbox').fill(name);
await this.page.waitForTimeout(1000);
}
/**
* 验证员工是否存在
* @param name 员工姓名
* @returns 是否存在
*/
async verifyEmployeeExists(name: string): Promise<boolean> {
const isVisible = await this.page.getByText(name).first().isVisible().catch(() => false);
return isVisible;
}
/**
* 新增员工完整流程
* @param name 员工姓名
* @param phone 联系电话
* @param remark 备注
* @param position 岗位(可选)
*/
async createEmployee(name: string, phone: string, remark: string, position?: string): Promise<void> {
await this.openEmployeeManagement();
await this.clickNewEmployee();
await this.clickManualAdd();
await this.fillEmployeeName(name);
await this.fillPhone(phone);
await this.fillRemark(remark);
await this.selectPosition(position);
await this.clickConfirm();
}
/**
* 点击修改按钮
*/
async clickEditButton(): Promise<void> {
await this.page.locator('uni-button.execute-plain-btn').getByText('修改').click();
await this.page.waitForTimeout(500);
}
/**
* 填写备注(修改页面)
* @param remark 备注信息
*/
async fillRemarkForEdit(remark: string): Promise<void> {
await this.page.locator('uni-input').filter({ hasText: '请输入备注信息' }).getByRole('textbox').click();
await this.page.locator('uni-input').filter({ hasText: '请输入备注信息' }).getByRole('textbox').fill(remark);
}
/**
* 点击状态开关
*/
async clickStatusSwitch(): Promise<void> {
await this.page.locator('uni-view:nth-child(5) > .nut-cell__value > .nut-form-item__body__slots > .nut-switch > .nut-switch-button').click();
await this.page.waitForTimeout(300);
}
/**
* 选择岗位(修改页面)
* @param position 岗位名称
*/
async selectPositionForEdit(position: string): Promise<void> {
// 点击岗位名称输入框打开下拉列表(使用与新增相同的selector)
await this.page.locator('uni-view:nth-child(6) > .nut-cell__value > .nut-form-item__body__slots > .nut-input > .nut-input__value > .nut-input__mask').click();
await this.page.waitForTimeout(500);
// 选择岗位
await this.page.locator('uni-view').filter({ hasText: position }).first().click();
await this.page.waitForTimeout(300);
}
/**
* 验证员工备注是否包含指定内容
* @param expectedRemark 期望的备注内容
* @returns 是否包含
*/
async verifyEmployeeRemarkContains(expectedRemark: string): Promise<boolean> {
const remarkElement = this.page.getByText(expectedRemark).first();
const isVisible = await remarkElement.isVisible({ timeout: 3000 }).catch(() => false);
return isVisible;
}
/**
* 点击解绑按钮
*/
async clickUnbindButton(): Promise<void> {
await this.page.locator('uni-button.warning-plain-btn').getByText('解绑').click();
await this.page.waitForTimeout(500);
}
/**
* 确认解绑
*/
async confirmUnbind(): Promise<void> {
await this.page.getByText('确定', { exact: true }).click();
await this.page.waitForTimeout(1000);
}
/**
* 验证员工不存在
* @param name 员工姓名
* @returns 是否不存在
*/
async verifyEmployeeNotExists(name: string): Promise<boolean> {
const employeeElement = this.page.getByText(name).first();
const isHidden = await employeeElement.isHidden({ timeout: 3000 }).catch(() => true);
return isHidden;
}
}