test(boss_cashier): 优化挂单测试流程
- 移除不必要的挂单数量记录步骤 - 简化挂单流程,每个员工只挂单一次 - 使用 expect.soft 进行软断言,提高测试稳定性 - 优化员工选择和挂单校验的代码结构
This commit is contained in:
parent
356a048508
commit
d44f457d86
@ -17,7 +17,7 @@
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@faker-js/faker": "^8.4.1",
|
||||
"@playwright/test": "^1.48.2",
|
||||
"@playwright/test": "^1.51.1",
|
||||
"@types/node": "^22.3.0",
|
||||
"axios": "^1.7.4",
|
||||
"cross-env": "^7.0.3"
|
||||
@ -31,7 +31,7 @@
|
||||
"ldap": "^0.7.1",
|
||||
"ldap-authentication": "^3.2.2",
|
||||
"ldapjs": "^3.0.7",
|
||||
"playwright": "^1.47.2",
|
||||
"playwright": "^1.51.1",
|
||||
"qrcode-reader": "^1.0.4",
|
||||
"sharp": "^0.33.5",
|
||||
"tesseract.js": "^5.1.1",
|
||||
|
||||
@ -87,7 +87,7 @@ module.exports = defineConfig({
|
||||
...devices['Desktop Chrome'],
|
||||
baseURL: process.env.BASE_URL,
|
||||
storageState: firstAuthFile,
|
||||
viewport: { width: 1280, height: 720 },
|
||||
// viewport: { width: 1280, height: 720 },
|
||||
isMobile: true,
|
||||
},
|
||||
testMatch: /.*boss_.*\.spec\.ts/,
|
||||
@ -99,7 +99,7 @@ module.exports = defineConfig({
|
||||
...devices['Desktop Safari'],
|
||||
baseURL: process.env.BASE_URL,
|
||||
storageState: firstAuthFile,
|
||||
viewport: { width: 1280, height: 720 },
|
||||
// viewport: { width: 1280, height: 720 },
|
||||
isMobile: true,
|
||||
},
|
||||
testMatch: /.*boss_.*\.spec\.ts/,
|
||||
@ -110,7 +110,7 @@ module.exports = defineConfig({
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
baseURL: process.env.BASE_URL,
|
||||
viewport: { width: 1280, height: 720 },
|
||||
// viewport: { width: 1280, height: 720 },
|
||||
isMobile: false,
|
||||
},
|
||||
testMatch: /.*staff_.*\.spec\.ts/,
|
||||
@ -121,7 +121,7 @@ module.exports = defineConfig({
|
||||
use: {
|
||||
...devices['Desktop Safari'],
|
||||
baseURL: process.env.BASE_URL,
|
||||
viewport: { width: 1280, height: 720 },
|
||||
// viewport: { width: 1280, height: 720 },
|
||||
isMobile: false,
|
||||
},
|
||||
testMatch: /.*staff_.*\.spec\.ts/,
|
||||
|
||||
9
tests/fixtures/baseFixture.ts
vendored
9
tests/fixtures/baseFixture.ts
vendored
@ -14,8 +14,13 @@ export const test = base.extend<MyFixture>({
|
||||
await expect(page.locator('.versionModal_main_content')).toBeVisible();
|
||||
});
|
||||
|
||||
if (!baseURL) throw new Error('baseURL is required');
|
||||
await page.goto(baseURL);
|
||||
try {
|
||||
await page.goto(baseURL!, { timeout: 90 * 1000 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
// await page.screenshot({ path: 'error.png' });
|
||||
await page.reload();
|
||||
}
|
||||
// await page.getByRole('button', { name: /开\s单/ }).waitFor();
|
||||
await expect(page.getByRole('button', { name: /开\s单/ })).toBeEnabled();
|
||||
|
||||
|
||||
@ -18,7 +18,13 @@ for (let testAccount of testAccountArray) {
|
||||
.locator('div', { has: page.getByRole('textbox', { name: '请输入您的手机号码' }) })
|
||||
.locator('.pass_svg');
|
||||
|
||||
await page.goto(baseURL!);
|
||||
try {
|
||||
await page.goto(baseURL!, { timeout: 90 * 1000 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
await page.bringToFront();
|
||||
await page.reload();
|
||||
}
|
||||
await page.getByRole('textbox', { name: '请输入您的手机号码' }).fill(account);
|
||||
await page.getByRole('textbox', { name: '请输入登录密码' }).fill(password);
|
||||
await page.getByLabel('请同意慧来客隐私政策和用户协议').check();
|
||||
@ -41,6 +47,6 @@ for (let testAccount of testAccountArray) {
|
||||
await page.getByRole('button', { name: /登\s录/ }).click();
|
||||
await page.getByRole('button', { name: /开\s单/ }).waitFor();
|
||||
}
|
||||
await page.context().storageState({ path: authFile });
|
||||
await page.context().storageState({ path: authFile, indexedDB: true });
|
||||
});
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ setup.describe('员工登录', () => {
|
||||
await page.getByLabel('请同意慧来客隐私政策和用户协议').check();
|
||||
await $login.click();
|
||||
await expect(page.getByRole('button', { name: /开\s单/ })).toBeEnabled();
|
||||
await page.context().storageState({ path: e.authFile });
|
||||
await page.context().storageState({ path: e.authFile, indexedDB: true });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -37,39 +37,15 @@ test.describe('挂单', () => {
|
||||
});
|
||||
|
||||
test('查看员工名下挂单', async ({ page, customerPage }) => {
|
||||
let OrderLQ = 0;
|
||||
let OrderZP = 0;
|
||||
|
||||
const $employeeBottom = page.locator('.userpanel_item');
|
||||
|
||||
await test.step('记录员工原挂单数量', async () => {
|
||||
|
||||
await expect(page.getByRole('button', { name: /^开\s单$/ })).toBeVisible();
|
||||
|
||||
// 点击底部员工刘强
|
||||
const EmployeeLQ = $employeeBottom.getByText(Employees.FirstShop.Employee_8.name);
|
||||
if (await EmployeeLQ.isVisible()) {
|
||||
await $employeeBottom.filter({ hasText: Employees.FirstShop.Employee_8.name }).click();
|
||||
await page.locator('.item_box').first().waitFor();
|
||||
OrderLQ = await page.locator('.item_box').count();
|
||||
} else {
|
||||
OrderLQ = 0;
|
||||
}
|
||||
|
||||
// 点击底部员工周萍
|
||||
const EmployeeZP = $employeeBottom.getByText(Employees.FirstShop.Employee_9.name);
|
||||
if (await EmployeeZP.isVisible()) {
|
||||
await $employeeBottom.filter({ hasText: Employees.FirstShop.Employee_9.name }).click();
|
||||
await page.locator('.item_box').first().waitFor();
|
||||
OrderZP = await page.locator('.item_box').count();
|
||||
} else {
|
||||
OrderZP = 0;
|
||||
}
|
||||
});
|
||||
const employeeLq = $employeeBottom.getByText(Employees.FirstShop.Employee_8.name);
|
||||
const employeeZp = $employeeBottom.getByText(Employees.FirstShop.Employee_9.name);
|
||||
|
||||
const $employeeLq = page.locator('.counselor:nth-child(2)').locator('.check_item:nth-child(1)').filter({ hasText: Employees.FirstShop.Employee_8.name });
|
||||
|
||||
await test.step('刘强挂单1', async () => {
|
||||
const $$pendingOrderCard = page.locator('.cash_content .list .item_box');
|
||||
|
||||
await test.step('刘强挂单', async () => {
|
||||
//员工1开第1单
|
||||
await page.getByRole('button', { name: /^开\s单$/ }).click();
|
||||
await customerPage.searchCustomer(phone);
|
||||
@ -84,46 +60,13 @@ test.describe('挂单', () => {
|
||||
await page.locator('button.save_and_copy').filter({ hasText: '保存并复制到其他项目/卖品' }).click();
|
||||
// 挂单
|
||||
await page.locator('#cart_bottom_btn').getByText('挂单').click();
|
||||
});
|
||||
|
||||
await test.step('刘强挂单2', async () => {
|
||||
//员工1开第2单
|
||||
await page.getByRole('button', { name: /^开\s单$/ }).click();
|
||||
await customerPage.searchCustomer(phone);
|
||||
await customerPage.selectSearchCustomer(username);
|
||||
|
||||
// 选择第三个项目
|
||||
await page.locator('.project_list').filter({ hasText: ProjectName.Projects.Projects_3.name }).click();
|
||||
// 选择添加员工
|
||||
await page.locator('button.staff_btn').click();
|
||||
// 选择员工:刘强
|
||||
await $employeeLq.click();
|
||||
// 保存并复制到其他项目
|
||||
await page.locator('button.save_and_copy').filter({ hasText: '保存并复制到其他项目/卖品' }).click();
|
||||
// 挂单
|
||||
await page.locator('#cart_bottom_btn').getByText('挂单').click();
|
||||
});
|
||||
|
||||
await test.step('刘强挂单3', async () => {
|
||||
//员工1开第3单
|
||||
await page.getByRole('button', { name: /^开\s单$/ }).click();
|
||||
await customerPage.searchCustomer(phone);
|
||||
await customerPage.selectSearchCustomer(username);
|
||||
// 选择第二个项目
|
||||
await page.locator('.project_list').filter({ hasText: ProjectName.Projects.Projects_2.name }).click();
|
||||
// 选择添加员工
|
||||
await page.locator('button.staff_btn').click();
|
||||
// 选择员工:刘强
|
||||
await $employeeLq.click();
|
||||
// 保存并复制到其他项目
|
||||
await page.locator('button.save_and_copy').filter({ hasText: '保存并复制到其他项目/卖品' }).click();
|
||||
// 挂单
|
||||
await page.locator('#cart_bottom_btn').getByText('挂单').click();
|
||||
await expect.soft($$pendingOrderCard.first()).toContainText(`${username}`);
|
||||
await expect($$pendingOrderCard.first()).toContainText(`${Employees.FirstShop.Employee_8.name}`);
|
||||
});
|
||||
|
||||
const $employeeZp = page.locator('.counselor:nth-child(2)').locator('.check_item:nth-child(1)').filter({ hasText: Employees.FirstShop.Employee_9.name });
|
||||
|
||||
await test.step('周萍挂单1', async () => {
|
||||
await test.step('周萍挂单', async () => {
|
||||
//员工2开第1单
|
||||
await page.getByRole('button', { name: /^开\s单$/ }).click();
|
||||
await customerPage.searchCustomer(phone);
|
||||
@ -140,41 +83,20 @@ test.describe('挂单', () => {
|
||||
await page.locator('button.save_and_copy').filter({ hasText: '保存并复制到其他项目/卖品' }).click();
|
||||
// 挂单
|
||||
await page.locator('#cart_bottom_btn').getByText('挂单').click();
|
||||
await expect.soft($$pendingOrderCard.first()).toContainText(`${username}`);
|
||||
await expect($$pendingOrderCard.first()).toContainText(`${Employees.FirstShop.Employee_9.name}`);
|
||||
});
|
||||
|
||||
await test.step('周萍挂单2', async () => {
|
||||
//员工2开第2单
|
||||
await page.getByRole('button', { name: /^开\s单$/ }).click();
|
||||
await customerPage.searchCustomer(phone);
|
||||
await customerPage.selectSearchCustomer(username);
|
||||
// 选择第二个项目
|
||||
await page.locator('.project_list').filter({ hasText: ProjectName.Projects.Projects_2.name }).click();
|
||||
// 选择添加员工
|
||||
await page.locator('button.staff_btn').click();
|
||||
// 选择员工:周萍
|
||||
await $employeeZp.click();
|
||||
// 保存并复制到其他项目
|
||||
await page.locator('button.save_and_copy').filter({ hasText: '保存并复制到其他项目/卖品' }).click();
|
||||
// 挂单
|
||||
await page.locator('#cart_bottom_btn').getByText('挂单').click();
|
||||
// 等待挂单成功
|
||||
await page.locator('.ant-message').waitFor();
|
||||
// 判断挂单成功弹窗消失后再执行下一步
|
||||
await expect(page.locator('.ant-message')).not.toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('最后校验挂单数量', async () => {
|
||||
await test.step('校验各个员工的挂单', async () => {
|
||||
// 点击底部员工刘强
|
||||
await $employeeBottom.filter({ hasText: Employees.FirstShop.Employee_8.name }).click();
|
||||
await page.locator('.item_box').first().waitFor();
|
||||
const order = await page.locator('.item_box').all();
|
||||
expect(order.length).toBe(3 + OrderLQ);
|
||||
await employeeLq.click();
|
||||
await expect.soft($$pendingOrderCard.first()).toContainText(`${username}`);
|
||||
await expect($$pendingOrderCard.first()).toContainText(`${Employees.FirstShop.Employee_8.name}`);
|
||||
|
||||
// 点击底部员工周萍
|
||||
await $employeeBottom.filter({ hasText: Employees.FirstShop.Employee_9.name }).click();
|
||||
await page.locator('.item_box').first().waitFor();
|
||||
const order1 = await page.locator('.item_box').all();
|
||||
expect(order1.length).toBe(2 + OrderZP);
|
||||
await employeeZp.click();
|
||||
await expect.soft($$pendingOrderCard.first()).toContainText(`${username}`);
|
||||
await expect($$pendingOrderCard.first()).toContainText(`${Employees.FirstShop.Employee_9.name}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user