customer.spec.ts
4.88 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
import { test, expect } from '../fixtures';
import { generateCustomerName, generateIdCard, generatePhoneNumber, generateDetailedAddress, generateCustomerInfo, getRandomImage } from '../utils/dataGenerator';
import * as allure from 'allure-js-commons';
/**
* 客户管理测试
*/
test.describe('客户管理', () => {
// 使用已保存的认证状态
test.use({ storageState: 'auth.json' });
test('新增客户', async ({ customerPage }, testInfo) => {
// 添加allure元素
await allure.epic('客户管理');
await allure.feature('客户信息');
await allure.story('创建新客户');
// 步骤1:生成随机客户信息
const customerInfo = await allure.step('生成随机客户信息', async (step) => {
const name = generateCustomerName();
const phone = generatePhoneNumber();
const idCard = generateIdCard();
const detailedAddress = generateDetailedAddress();
console.log('生成的客户信息:', { name, phone, idCard, detailedAddress });
return { name, phone, idCard, detailedAddress };
});
// 步骤2:执行新增客户操作
await allure.step('填写并提交客户表单', async () => {
await customerPage.gotoHome();
// 从 test-data/img 目录随机选择一张图片
const randomImage = getRandomImage();
await customerPage.createCustomer(
{
name: customerInfo.name,
phone: customerInfo.phone,
idCard: customerInfo.idCard,
detailedAddress: customerInfo.detailedAddress,
},
{
creditLimit: '500',
licensePlate: '渝ZY0706',
province: '江苏省',
city: '连云港市',
district: '海州区',
imagePath: randomImage || undefined, // 如果有图片则上传
}
);
await customerPage.attachScreenshot(testInfo, '新增客户成功截图');
});
// 步骤3:验证客户创建成功
await allure.step('验证客户创建成功', async () => {
const isCreated = await customerPage.verifyCustomerCreated(customerInfo.name);
expect(isCreated).toBeTruthy();
});
});
// test('新增客户 - 仅必填信息', async ({ customerPage }, testInfo) => {
// // 添加allure元素
// await allure.epic('客户管理');
// await allure.feature('客户信息');
// await allure.story('创建新客户(仅必填信息)');
// // 步骤1:生成随机客户信息
// const customerInfo = await allure.step('生成随机客户信息', async (step) => {
// const info = generateCustomerInfo();
// console.log('生成的客户信息:', info);
// return info;
// });
// // 步骤2:执行新增客户操作
// await allure.step('填写并提交客户表单(仅必填信息)', async () => {
// await customerPage.gotoHome();
// await customerPage.createCustomer({
// name: customerInfo.name,
// phone: customerInfo.phone,
// idCard: customerInfo.idCard,
// });
// await customerPage.attachScreenshot(testInfo, '新增客户成功截图');
// });
// // 步骤3:验证客户创建成功
// await allure.step('验证客户创建成功', async () => {
// const isCreated = await customerPage.verifyCustomerCreated(customerInfo.name);
// expect(isCreated).toBeTruthy();
// });
// });
// test('新增客户 - 带详细地址', async ({ customerPage }, testInfo) => {
// // 添加allure元素
// await allure.epic('客户管理');
// await allure.feature('客户信息');
// await allure.story('创建新客户(带详细地址)');
// // 步骤1:生成随机客户信息
// const customerInfo = await allure.step('生成随机客户信息', async (step) => {
// const name = generateCustomerName();
// const phone = generatePhoneNumber();
// const idCard = generateIdCard();
// const detailedAddress = generateDetailedAddress();
// console.log('生成的客户信息:', { name, phone, idCard, detailedAddress });
// return { name, phone, idCard, detailedAddress };
// });
// // 步骤2:执行新增客户操作
// await allure.step('填写并提交客户表单', async () => {
// await customerPage.gotoHome();
// await customerPage.createCustomer(
// {
// name: customerInfo.name,
// phone: customerInfo.phone,
// idCard: customerInfo.idCard,
// },
// {
// creditLimit: '10000',
// }
// );
// await customerPage.attachScreenshot(testInfo, '新增客户成功截图');
// });
// // 步骤3:验证客户创建成功
// await allure.step('验证客户创建成功', async () => {
// const isCreated = await customerPage.verifyCustomerCreated(customerInfo.name);
// expect(isCreated).toBeTruthy();
// });
// });
});