productCategory.spec.ts
5.89 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
import { test, expect } from '@playwright/test';
import * as allure from 'allure-js-commons';
import { ProductCategoryPage } from '../pages/productCategoryPage';
/**
* 商品分类测试
*/
test.describe('商品分类', () => {
// 使用已保存的认证状态
test.use({ storageState: 'auth.json' });
// 强制测试串行执行,避免并行测试之间的干扰
test.describe.configure({ mode: 'serial' });
/**
* 生成随机分类名称
*/
function generateCategoryName(): string {
const prefixes = ['畅销', '热卖', '新品', '精选', '推荐', '特惠', '优质', '普通'];
const timestamp = Date.now().toString().slice(-4);
return `${prefixes[Math.floor(Math.random() * prefixes.length)]}${timestamp}`;
}
test('新增商品分类', async ({ page }, testInfo) => {
const productCategoryPage = new ProductCategoryPage(page);
// 添加allure元素
await allure.epic('商品管理');
await allure.feature('商品分类');
await allure.story('新增商品分类');
// 生成随机分类名称
const categoryName = generateCategoryName();
const categoryDescription = '畅销的商品';
console.log('新增分类名称:', categoryName);
// 步骤1:进入商品分类页面
await allure.step('进入商品分类页面', async () => {
await productCategoryPage.openProductCategoryManagement();
});
// 步骤2:点击新增分类按钮
await allure.step('点击新增分类按钮', async () => {
await productCategoryPage.clickAddCategory();
});
// 步骤3:输入分类名称
await allure.step('输入分类名称', async () => {
await productCategoryPage.enterCategoryName(categoryName);
});
// 步骤4:输入分类描述
await allure.step('输入分类描述', async () => {
await productCategoryPage.enterCategoryDescription(categoryDescription);
});
// 步骤5:状态默认启用,点击确定
await allure.step('点击确定按钮', async () => {
await productCategoryPage.clickConfirm();
});
// 步骤6:搜索新增的分类
await allure.step('搜索新增的分类', async () => {
await productCategoryPage.searchCategory(categoryName);
});
// 步骤7:验证分类创建成功
await allure.step('验证分类创建成功', async () => {
await productCategoryPage.expectCategoryVisible(categoryName);
});
});
test('修改商品分类', async ({ page }, testInfo) => {
const productCategoryPage = new ProductCategoryPage(page);
// 添加allure元素
await allure.epic('商品管理');
await allure.feature('商品分类');
await allure.story('修改商品分类');
// 先生成一个分类用于修改
const originalCategoryName = generateCategoryName();
const modifiedCategoryName = `修改${originalCategoryName}`;
const originalDescription = '原始描述';
const modifiedDescription = '修改后的描述';
console.log('原分类名称:', originalCategoryName);
console.log('修改后分类名称:', modifiedCategoryName);
// 步骤1:先创建分类
await allure.step('创建待修改的分类', async () => {
await productCategoryPage.createCategory(originalCategoryName, originalDescription);
});
// 步骤2:搜索分类并点击修改
await allure.step('搜索并点击修改分类', async () => {
await productCategoryPage.searchCategory(originalCategoryName);
await productCategoryPage.clickEditCategory();
});
// 步骤3:修改分类名称
await allure.step('修改分类名称', async () => {
await productCategoryPage.enterCategoryName(modifiedCategoryName);
});
// 步骤4:修改分类描述
await allure.step('修改分类描述', async () => {
await productCategoryPage.enterCategoryDescription(modifiedDescription);
});
// 步骤5:切换状态(可选)
await allure.step('切换分类状态', async () => {
await productCategoryPage.toggleCategoryStatus();
});
// 步骤6:点击确定保存
await allure.step('保存修改', async () => {
await productCategoryPage.clickConfirm();
});
// 步骤7:清除搜索框并搜索修改后的分类
await allure.step('搜索修改后的分类', async () => {
await productCategoryPage.clearSearch();
await productCategoryPage.searchCategory(modifiedCategoryName);
});
// 步骤8:验证分类修改成功
await allure.step('验证分类修改成功', async () => {
await productCategoryPage.expectCategoryVisible(modifiedCategoryName);
});
});
test('删除商品分类', async ({ page }, testInfo) => {
const productCategoryPage = new ProductCategoryPage(page);
// 添加allure元素
await allure.epic('商品管理');
await allure.feature('商品分类');
await allure.story('删除商品分类');
// 先生成一个分类用于删除
const categoryName = generateCategoryName();
console.log('删除分类名称:', categoryName);
// 步骤1:先创建分类
await allure.step('创建待删除的分类', async () => {
await productCategoryPage.createCategory(categoryName, '删除测试描述');
});
// 步骤2:搜索分类
await allure.step('搜索待删除的分类', async () => {
await productCategoryPage.searchCategory(categoryName);
await productCategoryPage.expectCategoryVisible(categoryName);
});
// 步骤3:点击删除分类
await allure.step('点击删除分类按钮', async () => {
await productCategoryPage.clickDeleteCategory();
});
// 步骤4:确认删除
await allure.step('确认删除', async () => {
await productCategoryPage.clickConfirm();
});
// 步骤5:验证分类已删除
await allure.step('验证分类已删除', async () => {
await productCategoryPage.expectCategoryNotVisible(categoryName);
});
});
});