supplier.spec.ts
7.53 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
import { test, expect } from '../fixtures';
import * as allure from 'allure-js-commons';
/**
* 供应商管理测试
*/
test.describe('供应商管理', () => {
// 使用已保存的认证状态
test.use({ storageState: 'auth.json' });
// 强制测试串行执行,避免并行测试之间的干扰
test.describe.configure({ mode: 'serial' });
test('新建供应商并绑定园区卡', async ({ supplierPage }, testInfo) => {
await allure.epic('供应商管理');
await allure.feature('供应商信息');
await allure.story('新建供应商');
// 步骤1:生成随机供应商信息
const supplierInfo = await allure.step('生成随机供应商信息', async () => {
const info = await supplierPage.generateRandomSupplierInfo();
console.log('供应商名称:', info.name);
console.log('负责人:', info.managerName);
console.log('手机号:', info.phone);
console.log('备注:', info.remark);
return info;
});
// 步骤2:填写并提交供应商表单
await allure.step('填写并提交供应商表单', async () => {
await supplierPage.navigateToSupplierManagement();
await supplierPage.clickAddSupplier();
await supplierPage.fillFormField(supplierPage.supplierNameInput, supplierInfo.name);
await supplierPage.selectGroup();
await supplierPage.fillFormField(supplierPage.managerNameInput, supplierInfo.managerName);
await supplierPage.fillFormField(supplierPage.phoneInput, supplierInfo.phone);
await supplierPage.selectParkCard('888810046477', '地利');
await supplierPage.fillFormField(supplierPage.remarkInput, supplierInfo.remark || '');
await supplierPage.saveButton.click();
await supplierPage.attachScreenshot(testInfo, '新建供应商成功截图');
});
// 步骤3:验证供应商创建成功
await allure.step('验证供应商创建成功', async () => {
const isCreated = await supplierPage.verifySupplierCreated(supplierInfo.name);
expect(isCreated).toBeTruthy();
});
});
test('编辑供应商并绑定园区卡', async ({ supplierPage }, testInfo) => {
await allure.epic('供应商管理');
await allure.feature('供应商信息');
await allure.story('编辑供应商');
// 步骤1:生成新的供应商信息
const supplierInfo = await allure.step('生成新的供应商信息', async () => {
const namePrefixes = ['修改', '更新', '调整', '变更'];
const namePrefix = namePrefixes[Math.floor(Math.random() * namePrefixes.length)];
const info = await supplierPage.generateRandomSupplierInfo({
namePrefix: namePrefix,
});
console.log('新供应商名称:', info.name);
console.log('新负责人:', info.managerName);
console.log('新手机号:', info.phone);
console.log('新备注:', info.remark);
return info;
});
// 步骤2:填写并提交供应商表单
await allure.step('填写并提交供应商表单', async () => {
await supplierPage.navigateToSupplierManagement();
await supplierPage.clickSupplierItemByIndex(0);
await supplierPage.clickEditButton();
await supplierPage.clearAndFillFormField(supplierPage.supplierNameInput, supplierInfo.name);
await supplierPage.clearAndFillFormField(supplierPage.managerNameInput, supplierInfo.managerName);
await supplierPage.clearAndFillFormField(supplierPage.phoneInput, supplierInfo.phone);
await supplierPage.selectSupplierType();
await supplierPage.selectParkCard('888800010617');
await supplierPage.clearAndFillFormField(supplierPage.remarkInput, supplierInfo.remark || '');
await supplierPage.clickConfirmButton();
await supplierPage.attachScreenshot(testInfo, '编辑供应商成功截图');
});
// 步骤3:验证供应商修改成功
await allure.step('验证供应商修改成功', async () => {
const isUpdated = await supplierPage.verifySupplierCreated(supplierInfo.name);
expect(isUpdated).toBeTruthy();
});
});
test('删除供应商(金额都为0)', async ({ supplierPage }, testInfo) => {
await allure.epic('供应商管理');
await allure.feature('供应商信息');
await allure.story('删除供应商');
// 步骤1:进入供应商管理页面
await allure.step('进入供应商管理页面', async () => {
await supplierPage.navigateToSupplierManagement();
});
// 步骤2:查找并点击金额都为0的供应商
await allure.step('查找并点击金额都为0的供应商', async () => {
const found = await supplierPage.clickSupplierWithZeroAmounts();
expect(found).toBeTruthy();
});
// 步骤3:点击删除按钮
await allure.step('点击删除按钮', async () => {
await supplierPage.clickDeleteButton();
});
// 步骤4:确认删除
await allure.step('确认删除', async () => {
await supplierPage.confirmDelete();
await supplierPage.attachScreenshot(testInfo, '删除供应商成功截图');
});
});
test('录入欠款并验证应付金额增加', async ({ supplierPage }, testInfo) => {
await allure.epic('供应商管理');
await allure.feature('供应商信息');
await allure.story('录入欠款');
// 录入的欠款金额
const debtAmount = '100';
const remark = '测试录入欠款';
// 步骤1:进入供应商管理页面并选择第2个供应商,记录原始应付金额和供应商名称
let supplierName = '';
const originalAmount = await allure.step('记录原始应付金额', async () => {
await supplierPage.navigateToSupplierManagement();
await supplierPage.clickSupplierItemByIndex(1);
await supplierPage.waitForPageLoad();
await supplierPage.wait(300);
supplierName = await supplierPage.getSupplierName();
return await supplierPage.parsePayableAmount();
});
console.log('录入前应付金额:', originalAmount);
// 步骤2:点击录入欠款
await allure.step('点击录入欠款', async () => {
await supplierPage.clickRecordDebt();
});
// 步骤3:选择欠款方向(我方欠供应商)
await allure.step('选择欠款方向', async () => {
await supplierPage.selectDebtDirection('oweSupplier');
});
// 步骤4:选择赊欠日期(今日)
await allure.step('选择赊欠日期', async () => {
await supplierPage.selectDebtDate();
});
// 步骤5:填写赊欠金额
await allure.step('填写赊欠金额', async () => {
await supplierPage.fillDebtAmount(debtAmount);
});
// 步骤6:填写备注
await allure.step('填写备注', async () => {
await supplierPage.fillRemark(remark);
});
// 步骤7:保存欠款记录
await allure.step('保存欠款记录', async () => {
await supplierPage.saveDebt();
});
// 步骤8:验证欠款录入成功 - 搜索同一供应商查看应付金额
const currentAmount = await allure.step('验证欠款录入成功', async () => {
await supplierPage.navigateToSupplierManagement();
await supplierPage.clickSupplierItemByIndex(1);
await supplierPage.page.waitForLoadState('networkidle');
await supplierPage.page.waitForTimeout(300);
const amount = await supplierPage.parsePayableAmount();
console.log('录入后应付金额:', amount);
return amount;
});
// 验证应付金额增加了录入的金额
expect(currentAmount).toBeCloseTo(originalAmount + parseFloat(debtAmount), 1);
await supplierPage.attachScreenshot(testInfo, '录入欠款成功截图');
});
});