consignmentPage.ts
10.5 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import { Page, Locator, expect } from '@playwright/test';
import { BasePage } from './basePage';
/**
* 代销入库页面选择器
*/
const selectors = {
// 导航
moreMenu: 'text=更多',
consignmentInMenu: 'text=代销入库',
addConsignmentButton: 'text=新增代卖入库',
// 仓库选择
warehouseSelector: '.nut-input__mask',
warehouseOption: (warehouseName: string) => `uni-view:has-text("${warehouseName}")`,
mainTitleOption: '.mainTitle',
// 批次别名输入
batchAliasInput: 'uni-input:has-text("请输入批次别名") input',
// 商品选择
productListButton: 'text=商品清单点击选择商品',
productOption: (productName: string) => `text=${productName}`,
numberKey: (key: string) => `text=${key}`,
// 费用
addExpenseButton: 'text=入库费用添加费用',
expenseItem: '.box-item',
amountInput: '[role="spinbutton"]',
paymentItem: '.payment-item',
// 操作
createButton: 'text=创建',
saveButton: 'text=保存',
doneButton:'text=完成',
// 验证
batchNameInList: (batchName: string) => `uni-scroll-view:has-text("${batchName}")`,
};
/**
* 代销入库页面类
* 处理代销入库相关操作
*/
export class ConsignmentPage extends BasePage {
// 导航定位器
readonly moreMenu: Locator;
readonly consignmentInMenu: Locator;
readonly addConsignmentButton: Locator;
// 仓库选择
readonly warehouseSelector: Locator;
readonly mainTitleOption: Locator;
// 批次别名
readonly batchAliasInput: Locator;
// 商品选择
readonly productListButton: Locator;
// 费用
readonly addExpenseButton: Locator;
readonly expenseItem: Locator;
readonly amountInput: Locator;
readonly paymentItem: Locator;
// 操作按钮
readonly createButton: Locator;
readonly saveButton: Locator;
readonly doneButton:Locator;
constructor(page: Page) {
super(page);
this.moreMenu = page.getByText('更多');
this.consignmentInMenu = page.getByText('代销入库').first();
this.addConsignmentButton = page.getByText('新增代卖入库');
this.warehouseSelector = page.locator('.nut-input__mask').first();
this.mainTitleOption = page.locator('.mainTitle').first();
this.batchAliasInput = page.locator('uni-input').filter({ hasText: '请输入批次别名' }).getByRole('textbox');
this.productListButton = page.getByText('商品清单点击选择商品');
this.addExpenseButton = page.getByText('入库费用添加费用');
this.expenseItem = page.locator('.box-item');
this.amountInput = page.getByRole('spinbutton');
this.paymentItem = page.locator('.payment-item');
this.createButton = page.getByText('创建', { exact: true });
this.saveButton = page.getByText('保存');
this.doneButton = page.getByText('完成')
}
/**
* 导航到首页并等待加载
*/
async gotoHome(): Promise<void> {
await this.navigate('/');
await this.page.waitForLoadState('networkidle', { timeout: 30000 });
}
/**
* 打开更多菜单
*/
async openMoreMenu(): Promise<void> {
await this.moreMenu.click();
}
/**
* 打开代销入库菜单
*/
async openConsignmentIn(): Promise<void> {
await this.consignmentInMenu.click();
}
/**
* 点击新增代卖入库
*/
async clickAddConsignment(): Promise<void> {
await this.addConsignmentButton.click();
}
/**
* 导航到新增代销入库页面(完整流程)
*/
async navigateToNewConsignment(): Promise<void> {
await this.gotoHome();
await this.openMoreMenu();
await this.openConsignmentIn();
await this.clickAddConsignment();
}
/**
* 选择仓库
* @param warehouseName 仓库名称(可选,默认选择第一个)
*/
async selectWarehouse(warehouseName?: string): Promise<void> {
// 点击仓库选择器
await this.warehouseSelector.click();
if (warehouseName) {
// 选择指定仓库
await this.page.locator('uni-view').filter({ hasText: new RegExp(`^${warehouseName}$`) }).nth(1).click();
} else {
// 默认选择第一个
await this.mainTitleOption.click();
}
}
/**
* 选择第二个仓库
*/
async selectSecondWarehouse(): Promise<void> {
await this.page.locator('uni-view:nth-child(4) > .nut-cell__value > .nut-form-item__body__slots > .nut-input > .nut-input__value > .nut-input__mask').click();
await this.page.locator('uni-view').filter({ hasText: /^东区普通仓库$/ }).nth(1).click();
}
/**
* 输入批次别名
* @param alias 批次别名
*/
async enterBatchAlias(alias: string): Promise<void> {
await this.batchAliasInput.click();
await this.batchAliasInput.clear();
await this.batchAliasInput.fill(alias);
}
/**
* 打开商品选择列表
*/
async openProductList(): Promise<void> {
await this.productListButton.click();
}
// /**
// * 获取商品列表中所有可用的商品名称
// * @returns 商品名称数组
// */
// async getAvailableProducts(): Promise<string[]> {
// // 等待商品列表加载
// await this.page.locator('.productName').first().waitFor({ state: 'visible', timeout: 5000 });
// // 获取所有商品名称
// const productElements = await this.page.locator('.productName').allTextContents();
// return productElements.filter(name => name.trim() !== '');
// }
// /**
// * 随机选择一个商品
// * @returns 随机选择的商品名称
// */
// async selectRandomProduct(): Promise<string> {
// const products = await this.getAvailableProducts();
// if (products.length === 0) {
// throw new Error('商品列表为空,无法选择商品');
// }
// const randomIndex = Math.floor(Math.random() * products.length);
// const selectedProduct = products[randomIndex];
// console.log(`随机选择的商品: ${selectedProduct}`);
// return selectedProduct;
// }
/**
* 选择商品
* @param productName 商品名称
*/
async selectProduct(productName: string): Promise<void> {
// 在商品选择弹窗中选择商品,使用first()避免多个匹配项导致的strict mode violation
await this.page.locator('.productName').getByText(productName).click();
}
/**
* 输入商品数量
* @param quantity 数量(数字字符串,如 "10")
*/
async enterProductQuantity(quantity: string): Promise<void> {
for (const digit of quantity) {
await this.page.getByText(digit, { exact: true }).click();
}
}
/**
* 完成商品选择
*/
async completeProductSelection(): Promise<void> {
await this.doneButton.click(); // 点击完成按钮(同保存按钮)
await this.saveButton.click()
}
/**
* 选择商品并输入数量
* @param productName 商品名称
* @param quantity 数量
*/
async selectProductWithQuantity(productName: string, quantity: string): Promise<void> {
await this.openProductList();
await this.selectProduct(productName);
await this.enterProductQuantity(quantity);
await this.completeProductSelection();
}
/**
* 添加费用项
* @param expenseIndex 费用项索引(默认第一个)
* @param amount 金额
*/
async addExpense(expenseIndex: number = 0, amount: string = '1'): Promise<void> {
// 打开费用选择
await this.addExpenseButton.click();
// 等待费用列表加载
await this.expenseItem.first().waitFor({ state: 'attached' });
// 选择费用项
await this.expenseItem.nth(expenseIndex).click();
await this.page.getByText('确定').click();
// 输入金额
await this.page.getByText('金额*0.00').click();
await this.amountInput.click();
await this.amountInput.fill(amount);
}
/**
* 选择支付方式
* @param paymentIndex 支付方式索引(默认第一个)
*/
async selectPaymentMethod(paymentIndex: number = 0): 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.paymentItem.first().waitFor({ state: 'attached' });
// 选择支付方式
await this.paymentItem.nth(paymentIndex).click();
await this.page.getByText('确定').click();
}
/**
* 点击创建按钮
*/
async clickCreate(): Promise<void> {
await this.createButton.click();
}
/**
* 等待创建完成
*/
async waitForCreationComplete(): Promise<void> {
await this.page.waitForLoadState('networkidle');
await this.wait(1000); // 额外等待1秒,适配uni-app页面渲染延迟
}
/**
* 验证批次创建成功
* @param batchName 批次名称
*/
async expectBatchCreated(batchName: string): Promise<void> {
await expect(this.page.locator('uni-scroll-view').getByText(batchName)).toBeVisible();
}
/**
* 完整的代销入库创建流程
* @param batchAlias 批次别名
* @param productName 商品名称
* @param quantity 数量
* @param amount 费用金额
*/
async createConsignmentOrder(
batchAlias: string,
productName: string,
quantity: string = '10',
amount: string = '1'
): Promise<void> {
// 导航到新增页面
await this.navigateToNewConsignment();
// 选择仓库
await this.selectWarehouse();
await this.selectSecondWarehouse();
// 输入批次别名
await this.enterBatchAlias(batchAlias);
// 选择商品
await this.selectProductWithQuantity(productName, quantity);
// 添加费用
await this.addExpense(0, amount);
await this.selectPaymentMethod(0);
// 创建
await this.clickCreate();
await this.waitForCreationComplete();
// 验证
await this.expectBatchCreated(batchAlias);
}
/**
* 简化的代销入库创建流程(不添加费用)
* @param batchAlias 批次别名
* @param productName 商品名称
* @param quantity 数量
*/
async createSimpleConsignmentOrder(
batchAlias: string,
productName: string,
quantity: string = '10'
): Promise<void> {
// 导航到新增页面
await this.navigateToNewConsignment();
// 选择仓库
await this.selectWarehouse();
await this.selectSecondWarehouse();
// 输入批次别名
await this.enterBatchAlias(batchAlias);
// 选择商品
await this.selectProductWithQuantity(productName, quantity);
// 创建
await this.clickCreate();
await this.waitForCreationComplete();
}
}