ci(test): 更新 Playwright 版本并优化测试脚本

- 将 Playwright 版本从 v1.43.0 升级到 v1.51.0
- 优化了 baseFixture 中的登录流程
- 改进了 customerPage 中的顾客创建逻辑
- 调整了 boss_cashier 和 staff_goal 测试中的操作方式
This commit is contained in:
LingandRX 2025-03-16 19:10:03 +08:00
parent fad6c46850
commit bac0dbfdbe
5 changed files with 66 additions and 37 deletions

View File

@ -1,6 +1,6 @@
playwright_tests: playwright_tests:
stage: test stage: test
image: mcr.microsoft.com/playwright:v1.43.0-jammy image: mcr.microsoft.com/playwright:v1.51.0-noble
cache: cache:
key: $CI_COMMIT_REF_SLUG key: $CI_COMMIT_REF_SLUG
paths: paths:
@ -9,7 +9,7 @@ playwright_tests:
- npm config set registry https://registry.npmmirror.com - npm config set registry https://registry.npmmirror.com
script: script:
- npm install - npm install
- npx playwright test - npx playwright test /touch/boss_cashier.spec.ts --grep "挂单" --project '慧来客touch(管理员身份) - Desktop Chrome'
artifacts: artifacts:
paths: paths:
- test-results/ - test-results/

View File

@ -24,7 +24,9 @@ export const test = base.extend<MyFixture>({
await page.getByRole('button', { name: /开\s单/ }).click(); await page.getByRole('button', { name: /开\s单/ }).click();
// await page.getByRole('button', { name: /开\s单/ }).waitFor(); // await page.getByRole('button', { name: /开\s单/ }).waitFor();
await expect(page.getByRole('button', { name: '创建会员' })).toBeEnabled(); await expect(page.getByRole('button', { name: '创建会员' })).toBeEnabled();
await page.locator('.top > .anticon').first().click();
await expect(page.getByRole('button', { name: '创建会员' })).not.toBeVisible();
await expect(page.getByRole('button', { name: /开\s单/ })).toBeInViewport();
await use(page); await use(page);
}, },

View File

@ -339,22 +339,55 @@ export class CustomerPage {
* @param {string} phone * @param {string} phone
*/ */
private readonly confirmCreation = async (phone: string) => { private readonly confirmCreation = async (phone: string) => {
try {
// 等待响应并点击按钮
const [response] = await Promise.all([ const [response] = await Promise.all([
this.page.waitForResponse(async res => res.url().includes('/invalid_check') && (await res.json()).code === 'SUCCESS'), this.page.waitForResponse(async (res) => {
const urlMatch = res.url().includes('/invalid_check');
if (!urlMatch) return false;
try {
const json = await res.json();
return json.code === 'SUCCESS';
} catch (e) {
console.error('解析响应体失败:', e);
return false;
}
}),
this.page.getByRole('button', { name: '确认创建' }).click(), this.page.getByRole('button', { name: '确认创建' }).click(),
]); ]);
const responseBody = await response.json();
const phoneStatus = responseBody?.content?.status; // 解析响应体
if (phoneStatus === undefined || phoneStatus === null) { let responseBody: any;
// 创建顾客成功 try {
return; responseBody = await response.json();
} catch (e) {
throw new Error('无法解析服务器响应体,请检查网络连接或服务器状态');
} }
await this.page.getByText('系统查询到当前手机号被建档后转为无效客,是否要恢复无效客?').waitFor();
await this.page.getByRole('button', { name: '重新建档' }).click();
const popupWindow = this.page.locator('.ant-message');
await expect(popupWindow).not.toContainText('该手机号码已经被使用'); // 检查响应体内容
if (responseBody && typeof responseBody.content === 'object') {
const phoneStatus = responseBody.content?.status;
if (phoneStatus != null) {
throw new Error(`手机号码 ${phone} 已被使用,无法创建新顾客`);
}
} else {
console.warn('响应体格式不符合预期content 不是对象');
}
} catch (error) {
// 捕获并记录异常
console.error('检查手机号码时发生错误:', error);
throw error; // 重新抛出异常以便调用方处理
}
// if (phoneStatus === undefined || phoneStatus === null) {
// 创建顾客成功
// return;
// }
// await this.page.getByText('系统查询到当前手机号被建档后转为无效客,是否要恢复无效客?').waitFor();
// await this.page.getByRole('button', { name: '重新建档' }).click();
// const popupWindow = this.page.locator('.ant-message');
// await expect(popupWindow).not.toContainText('该手机号码已经被使用');
// await popupWindow.waitFor(); // await popupWindow.waitFor();
// const popupContent = (await popupWindow.innerText()).trim(); // const popupContent = (await popupWindow.innerText()).trim();

View File

@ -276,27 +276,21 @@ test.describe('挂单', () => {
}); });
test('已过期单据不能取单,只能删除', async ({ page }) => { test('已过期单据不能取单,只能删除', async ({ page }) => {
const $slidingMenu = page.locator('div.deleteList .m_sliding_menu');
await page.getByText('已过期 / 删除单据').click(); await page.getByText('已过期 / 删除单据').click();
await page.getByText('警告:已过期服务无法取单结算,请至收银台处理').waitFor(); await page.getByText('警告:已过期服务无法取单结算,请至收银台处理').waitFor();
await $slidingMenu.locator('div.item_box').first().waitFor();
await expect(
$slidingMenu
.locator('div.item_box')
.first()
.getByRole('button', { name: /^取\s单$/ }),
).not.toBeVisible();
const $delete = $slidingMenu const $firstOrder = page.locator('.deleteList .m_sliding_menu .item_box').first();
.locator('div.item_box')
.first() await expect($firstOrder.getByRole('button', { name: /^取\s单$/ })).not.toBeVisible();
.locator('.comment > div:nth-child(2) > .touchIcon');
await $delete.click(); await $firstOrder.locator('.comment > div:nth-child(2) > .touchIcon').click();
await page.getByPlaceholder('请输入1-100个字符备注内容').click(); await page.getByPlaceholder('请输入1-100个字符备注内容').click();
await page.getByPlaceholder('请输入1-100个字符备注内容').fill('测试备注'); await page.getByPlaceholder('请输入1-100个字符备注内容').fill('测试备注');
await page.getByRole('button', { name: /^保\s存$/ }).click(); await Promise.all([
await expect(page.locator('.ant-message').filter({ hasText: '删除成功' }).nth(2)).toBeVisible(); page.getByRole('button', { name: /^保\s存$/ }).click(),
expect(page.locator('.ant-message').filter({ hasText: '删除成功' })).toBeVisible(),
]);
}); });
}); });
@ -306,7 +300,7 @@ test.describe('挂单', () => {
const phone = customer.phone; const phone = customer.phone;
const username = customer.username; const username = customer.username;
await page.pause(); // await page.pause();
await homeNavigation.gotoModule('收银'); await homeNavigation.gotoModule('收银');
await page.getByRole('button', { name: /^开\s单$/ }).click(); await page.getByRole('button', { name: /^开\s单$/ }).click();

View File

@ -48,7 +48,7 @@ test.describe('目标-目标设置', () => {
.locator('.m-table-cell') .locator('.m-table-cell')
.nth(1) .nth(1)
.click(); .click();
await numberInput.setValue(Number(goal)); await numberInput.setValue('common', Number(goal));
await numberInput.confirmValue(); await numberInput.confirmValue();
await page.getByRole('button', { name: '保 存' }).click(); await page.getByRole('button', { name: '保 存' }).click();
@ -101,7 +101,7 @@ test.describe('目标-目标设置', () => {
.locator('.m-table-cell') .locator('.m-table-cell')
.nth(1) .nth(1)
.click(); .click();
await numberInput.setValue(0); await numberInput.setValue('common', 0);
await numberInput.confirmValue(); await numberInput.confirmValue();
await page.getByRole('button', { name: '保 存' }).click(); await page.getByRole('button', { name: '保 存' }).click();
}); });
@ -191,7 +191,7 @@ test.describe('目标-目标设置', () => {
const code = page.locator('.popupComTableStyle .m-table__body .main-table-body_tr'); const code = page.locator('.popupComTableStyle .m-table__body .main-table-body_tr');
await code.nth(nowRowB).locator('.m-table-cell').nth(1).click(); await code.nth(nowRowB).locator('.m-table-cell').nth(1).click();
await numberInput.setValue(Number(goalB)); await numberInput.setValue('common', Number(goalB));
await numberInput.confirmValue(); await numberInput.confirmValue();
// 员工C内行数 // 员工C内行数
@ -217,7 +217,7 @@ test.describe('目标-目标设置', () => {
).not.toBeVisible(); ).not.toBeVisible();
await code.nth(nowRowC).locator('.m-table-cell').nth(1).click(); await code.nth(nowRowC).locator('.m-table-cell').nth(1).click();
await numberInput.setValue(Number(goalC)); await numberInput.setValue('common', Number(goalC));
await numberInput.confirmValue(); await numberInput.confirmValue();
await page.getByRole('button', { name: /保\s存/ }).click(); await page.getByRole('button', { name: /保\s存/ }).click();