customerGroup.spec.ts
4.43 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
import { test, expect } from '@playwright/test';
import * as allure from 'allure-js-commons';
import { CustomerGroupPage } from '../pages/customerGroupPage';
/**
* 客户分组测试
*/
test.describe('客户分组', () => {
// 使用已保存的认证状态
test.use({ storageState: 'auth.json' });
// 强制测试串行执行,避免并行测试之间的干扰
test.describe.configure({ mode: 'serial' });
/**
* 生成随机分组名称(5个字以内)
*/
function generateGroupName(): string {
const prefixes = ['测试', '客户', '优质', '普通', '会员', 'VIP', '大', '小', '新', '老'];
const suffixes = ['组', '户', '客', '户', '户'];
const prefix = prefixes[Math.floor(Math.random() * prefixes.length)];
const suffix = suffixes[Math.floor(Math.random() * suffixes.length)];
const timestamp = Date.now().toString().slice(-2);
const name = `${prefix}${suffix}${timestamp}`;
return name.slice(0, 5); // 确保不超过5个字
}
/**
* 生成随机排序号
*/
function generateSortNumber(): string {
return String(Math.floor(Math.random() * 999) + 1);
}
test('新增客户分组', async ({ page }, testInfo) => {
const customerGroupPage = new CustomerGroupPage(page);
// 添加allure元素
await allure.epic('客户管理');
await allure.feature('客户分组');
await allure.story('新增客户分组');
// 生成随机分组名称
const groupName = generateGroupName();
console.log('新增分组名称:', groupName);
// 步骤1:进入客户分组页面
await allure.step('进入客户分组页面', async () => {
await customerGroupPage.openCustomerGroupManagement();
});
// 步骤2:点击新建按钮
await allure.step('点击新建按钮', async () => {
await customerGroupPage.clickNewButton();
});
// 步骤3:填写分组信息
await allure.step('填写分组信息', async () => {
await customerGroupPage.fillGroupName(groupName);
});
// 步骤4:保存分组
await allure.step('保存分组', async () => {
await customerGroupPage.clickConfirm();
});
// 步骤5:验证分组创建成功
await allure.step('验证分组创建成功', async () => {
const isExists = await customerGroupPage.verifyGroupExists(groupName);
expect(isExists).toBeTruthy();
});
});
test('修改客户分组', async ({ page }, testInfo) => {
const customerGroupPage = new CustomerGroupPage(page);
// 添加allure元素
await allure.epic('客户管理');
await allure.feature('客户分组');
await allure.story('修改客户分组');
// 先生成一个分组用于修改
const originalGroupName = generateGroupName();
const newGroupName = generateGroupName();
const newSortNumber = generateSortNumber();
console.log('原分组名称:', originalGroupName);
console.log('新分组名称:', newGroupName);
// 步骤1:先创建分组
await allure.step('创建待修改的分组', async () => {
await customerGroupPage.createGroup(originalGroupName);
});
// 步骤2:修改分组
await allure.step('修改分组', async () => {
await customerGroupPage.updateGroup(originalGroupName, newGroupName, newSortNumber);
});
// 步骤3:验证分组修改成功
await allure.step('验证分组修改成功', async () => {
const isExists = await customerGroupPage.verifyGroupExists(newGroupName);
expect(isExists).toBeTruthy();
});
});
test('删除客户分组', async ({ page }, testInfo) => {
const customerGroupPage = new CustomerGroupPage(page);
// 添加allure元素
await allure.epic('客户管理');
await allure.feature('客户分组');
await allure.story('删除客户分组');
// 先生成一个分组用于删除
const groupName = generateGroupName();
console.log('待删除分组名称:', groupName);
// 步骤1:先创建分组
await allure.step('创建待删除的分组', async () => {
await customerGroupPage.createGroup(groupName);
});
// 步骤2:删除分组
await allure.step('删除分组', async () => {
await customerGroupPage.deleteGroup(groupName);
});
// 步骤3:验证分组删除成功
await allure.step('验证分组删除成功', async () => {
const isNotExists = await customerGroupPage.verifyGroupNotExists(groupName);
expect(isNotExists).toBeTruthy();
});
});
});