更新 Playwright 配置以保留失败时的追踪信息,重构测试用例以提高可读性和结构清晰度

This commit is contained in:
LingandRX 2024-11-09 22:03:13 +08:00
parent af98ccd0b8
commit 44a701cbed
3 changed files with 15 additions and 11 deletions

View File

@ -41,7 +41,7 @@ module.exports = defineConfig({
'Accept-Language': 'zh-CN,zh;q=0.9',
},
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
trace: 'retain-on-failure',
},
/* Configure projects for major browsers */

View File

@ -8,8 +8,11 @@ test.describe
const customer = new Customer(1, 1, { phone: phone });
console.log(`${customer.phone}-${customer.username}`);
test('登录touch和h5创建顾客购买会员卡', async ({ touchPage, touchCustomerPage }) => {
test('创建顾客', async ({ touchCustomerPage }) => {
await touchCustomerPage.createCustomer(customer);
});
test('登录touch和h5创建顾客购买会员卡', async ({ touchPage }) => {
await test.step('在touch页面购买会员卡', async () => {
await touchPage.getByText('去开单').click();
await touchPage.locator('.more > .icon > svg').click();

View File

@ -23,15 +23,15 @@ test('csv', async ({ zhbPage }, workerInfo) => {
console.log({ name, phone });
const customer = new Customer({ name: name, phone: name });
// 使用房间名称
/**@type {string} 房间名称 */
let useRoomName;
await test.step('购买商品', async () => {
await zhbPage.locator('#tab_main li').filter({ hasText: '营业' }).click();
const $emptyRoom = $$room
.filter({ has: zhbPage.getByText('空房') })
.nth(workerInfo.workerIndex % 3);
await $emptyRoom.locator('.roomName').waitFor();
useRoomName = await $emptyRoom.locator('.roomName').innerText();
expect(useRoomName).not.toBeNull();
await $emptyRoom.click();
await expect(async () => {
if (await zhbPage.locator('.close > .iconfont').first().isVisible()) {
@ -66,21 +66,22 @@ test('csv', async ({ zhbPage }, workerInfo) => {
.first()
.click();
await zhbPage.getByRole('button', { name: '完成开单' }).click();
await expect(zhbPage.getByRole('button', { name: '结账' })).toBeVisible({ timeout: 30_000 });
await expect(zhbPage.getByRole('button', { name: '结账' })).toBeVisible();
await zhbPage.getByRole('button', { name: '结账' }).click();
await zhbPage.locator('#page_footBathPay').getByText('结算签字').click();
await expect(async () => {
await zhbPage.locator('#page_footBathPay li').filter({ hasText: '现金' }).click();
await expect(zhbPage.locator('#page_footBathPay li').filter({ hasText: '现金' })).toHaveClass(
/selected/
/selected/,
{ timeout: 2000 }
);
await zhbPage
.locator('#page_footBathPay span')
.filter({ hasText: /结\s算/ })
.click();
await expect(zhbPage.getByText('顾客满意度点评')).toBeVisible({ timeout: 2000 });
}).toPass();
await zhbPage
.locator('#page_footBathPay span')
.filter({ hasText: /结\s算/ })
.click();
await expect(zhbPage.getByText('顾客满意度点评')).toBeVisible({ timeout: 2000 });
await zhbPage.getByText('不想评价').click();
await zhbPage.locator('#page_footBathPay').getByText('立即返回').click();