supplierGroupingPage.ts
5.62 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
import { Page, Locator } from '@playwright/test';
import { BasePage } from './basePage';
/**
* 供应商分组选择器
*/
const selectors = {
// 导航
moreMenu: 'text=更多 >',
supplierGroupingMenu: 'text=供应商分组',
addButton: 'text=新建',
// 表单字段
groupNameInput: 'uni-input:filter([placeholder*="分组名称"]) input',
remarkInput: 'uni-input:filter([placeholder*="备注"]) input',
// 操作按钮
confirmButton: 'text=确定',
saveButton: 'text=确定',
// 供应商分组列表
supplierGroupingList: '.supplier-grouping-list',
supplierGroupingItem: '.supplier-grouping-list .item',
};
/**
* 供应商分组页面类
* 处理供应商分组相关操作
*/
export class SupplierGroupingPage extends BasePage {
// 导航定位器
readonly moreMenu!: Locator;
readonly supplierGroupingMenu: Locator;
readonly addButton: Locator;
// 表单字段
readonly groupNameInput: Locator;
readonly remarkInput: Locator;
// 操作按钮
readonly confirmButton: Locator;
readonly saveButton: Locator;
constructor(page: Page) {
super(page);
// 导航
this.moreMenu = page.getByText('更多 >');
this.supplierGroupingMenu = page.getByText('供应商分组').first();
this.addButton = page.getByText('新建');
// 表单字段
this.groupNameInput = page.locator('uni-input').filter({ hasText: '请输入分组名称' }).getByRole('textbox');
this.remarkInput = page.locator('uni-input').filter({ hasText: '请输入备注' }).getByRole('textbox');
// 操作按钮
this.confirmButton = page.getByText('确定');
this.saveButton = page.getByText('确定');
}
/**
* 打开更多菜单
*/
async openMoreMenu(): Promise<void> {
await this.moreMenu.click();
await this.wait(500);
}
/**
* 打开供应商分组页面
*/
async openSupplierGrouping(): Promise<void> {
await this.supplierGroupingMenu.click({ force: true });
await this.waitForPageLoad();
await this.wait(500);
}
/**
* 点击新建分组按钮
*/
async clickAddButton(): Promise<void> {
await this.addButton.click();
await this.waitForPageLoad();
}
/**
* 填写分组名称
* @param name 分组名称
*/
async fillGroupName(name: string): Promise<void> {
await this.groupNameInput.click();
await this.groupNameInput.fill(name);
}
/**
* 填写备注
* @param remark 备注内容
*/
async fillRemark(remark: string): Promise<void> {
await this.remarkInput.click();
await this.remarkInput.fill(remark);
}
/**
* 保存分组
*/
async saveGrouping(): Promise<void> {
await this.saveButton.click();
await this.waitForPageLoad();
await this.wait(500);
}
/**
* 搜索分组
* @param groupName 分组名称
*/
async searchGrouping(groupName: string): Promise<void> {
await this.page.getByRole('textbox').click();
await this.wait(300);
await this.page.getByRole('textbox').fill(groupName);
await this.wait(1500);
await this.page.getByRole('textbox').press('Enter');
await this.wait(1000);
}
/**
* 验证分组是否创建成功
* @param groupName 分组名称
*/
async verifyGroupingCreated(groupName: string): Promise<boolean> {
try {
await this.navigateToSupplierGrouping();
await this.searchGrouping(groupName);
await this.page.waitForSelector(`uni-view:has-text("${groupName}")`, { timeout: 10000 });
return true;
} catch {
return false;
}
}
/**
* 进入供应商分组页面(完整流程)
*/
async navigateToSupplierGrouping(): Promise<void> {
await this.navigate('/');
await this.openMoreMenu();
await this.openSupplierGrouping();
}
/**
* 点击编辑分组按钮
*/
async clickEditButton(): Promise<void> {
await this.page.getByText('编辑').click();
await this.waitForPageLoad();
}
/**
* 修改分组
* @param groupName 新的分组名称
* @param remark 新的备注
*/
async updateGrouping(groupName: string, remark: string): Promise<void> {
await this.fillGroupName(groupName);
await this.fillRemark(remark);
await this.saveGrouping();
}
/**
* 验证分组是否修改成功
* @param groupName 分组名称
*/
async verifyGroupingUpdated(groupName: string): Promise<boolean> {
try {
await this.navigateToSupplierGrouping();
await this.searchGrouping(groupName);
await this.page.waitForSelector(`uni-view:has-text("${groupName}")`, { timeout: 10000 });
return true;
} catch {
return false;
}
}
/**
* 点击删除分组按钮
*/
async clickDeleteButton(): Promise<void> {
await this.page.getByText('删除', { exact: true }).click();
}
/**
* 点击分组项
* @param groupName 分组名称
*/
async clickGroupingItem(groupName: string): Promise<void> {
await this.page.locator('uni-view').filter({ hasText: new RegExp(`^${groupName}$`) }).first().click();
await this.waitForPageLoad();
}
/**
* 确认删除分组
*/
async confirmDelete(): Promise<void> {
await this.page.getByText('确定', { exact: true }).click();
await this.waitForPageLoad();
await this.wait(500);
}
/**
* 验证分组是否删除成功
* @param groupName 分组名称
*/
async verifyGroupingDeleted(groupName: string): Promise<boolean> {
try {
await this.navigateToSupplierGrouping();
await this.searchGrouping(groupName);
// 删除成功后,列表会显示"没有数据哦~"
await this.page.waitForSelector(`uni-view:has-text("No data")`, { timeout: 10000 });
return true;
} catch {
return false;
}
}
}