diff --git a/playwright.config.js b/playwright.config.js index 5d05fc1..668190b 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -26,7 +26,7 @@ module.exports = defineConfig({ /* Retry on CI only */ retries: process.env.CI ? 2 : 0, /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + workers: process.env.CI ? 1 : 1, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: 'html', /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ diff --git a/tests/zhb/demo.spec.js b/tests/zhb/demo.spec.js index 8984926..50e2684 100644 --- a/tests/zhb/demo.spec.js +++ b/tests/zhb/demo.spec.js @@ -1,105 +1,111 @@ +const { faker } = require('@faker-js/faker'); const { test, expect } = require('./fixture/common'); const { Customer } = require('./pom/customerPage'); -test('demo', async ({ zhbPage, customerPage }) => { - const $area = zhbPage - .locator('.area') - .filter({ has: zhbPage.locator('.area-name', { hasText: '二楼' }) }); - const $$room = $area.locator('.room-list .room'); +for (let i = 0; i < 50; i++) { + test(`demo${i}`, async ({ zhbPage, customerPage }, workerInfo) => { + const $area = zhbPage + .locator('.area') + .filter({ has: zhbPage.locator('.area-name', { hasText: '二楼' }) }); + const $$room = $area.locator('.room-list .room'); - const customer = new Customer(); - await test.step('创建顾客', async () => { - await zhbPage.locator('#tab_main li').filter({ hasText: '顾客' }).click(); - await customerPage.createCustomer(customer); - }); - - let useRoomName; - await test.step('购买商品', async () => { - await zhbPage.locator('#tab_main li').filter({ hasText: '营业' }).click(); - const $emptyRoom = $$room.filter({ has: zhbPage.getByText('空房') }).first(); - useRoomName = await $emptyRoom.locator('.roomName').innerText(); - expect(useRoomName).not.toBeNull(); - await $emptyRoom.click(); - await expect(async () => { - await zhbPage.getByRole('button', { name: '选择顾客' }).click(); - await expect(zhbPage.locator('#page_searchMember').getByText('创建会员')).toBeVisible(); - }).toPass(); - await zhbPage - .getByRole('textbox', { name: '输入会员手机号或姓名或卡号搜索' }) - .fill(customer.phone, { delay: 100 }); - await zhbPage.locator('#page_searchMember svg').click(); - - const $customerTr = zhbPage - .locator('.list-warp') - .filter({ has: zhbPage.locator('.name', { hasText: customer.name }) }); - await $customerTr.locator('.list-body').first().click(); - - await zhbPage.getByText('项目开单').click(); - await expect(zhbPage.locator('#page_roomDetail').getByText('服务项目')).toBeVisible(); - await zhbPage.getByText('选择', { exact: true }).nth(1).click(); - await expect(zhbPage.locator('#serviceSelector').getByText('项目选择')).toBeVisible(); - await zhbPage.getByText('臻品足疗 (10101)').click(); - await zhbPage.locator('#serviceSelector').getByText('确认').click(); - await zhbPage - .locator('div') - .filter({ hasText: /^匠星足浴$/ }) - .locator('span') - .first() - .click(); - await zhbPage.getByRole('button', { name: '完成开单' }).click(); - 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/ - ); - await zhbPage - .locator('#page_footBathPay span') - .filter({ hasText: /结\s算/ }) - .click(); - await expect(zhbPage.getByText('顾客满意度点评')).toBeVisible({ timeout: 2000 }); - }).toPass(); - - await zhbPage.getByText('不想评价').click(); - await expect(zhbPage.locator('#page_footBathPay').getByText('立即返回')).not.toBeVisible(); - }); - - await test.step('起钟下钟,清理房间', async () => { - const $cleanRoom = $$room.filter({ - has: zhbPage.locator('.roomName', { hasText: new RegExp(`^${useRoomName}$`) }), + const customer = new Customer(); + await test.step('创建顾客', async () => { + await zhbPage.locator('#tab_main li').filter({ hasText: '顾客' }).click(); + await customerPage.createCustomer(customer); }); - await expect($cleanRoom).toContainText('已结清'); - await $cleanRoom.click(); - await zhbPage.getByText('技师操作').click(); - await zhbPage.getByText('起钟', { exact: true }).click(); - await zhbPage.getByText('起钟成功!').click(); - await zhbPage.getByText('技师操作').click(); - await zhbPage.getByText('下钟', { exact: true }).click(); - await zhbPage - .locator('div') - .filter({ hasText: /^确认返回$/ }) - .locator('div') - .first() - .click(); - await zhbPage.getByRole('button', { name: '不需要' }).click(); - await expect($cleanRoom).toContainText('打扫'); - await $cleanRoom.click(); - await zhbPage - .locator('div') - .filter({ hasText: /^确定取消$/ }) - .locator('div') - .first() - .click(); - await expect($cleanRoom).toContainText('空房'); + 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); + useRoomName = await $emptyRoom.locator('.roomName').innerText(); + expect(useRoomName).not.toBeNull(); + await $emptyRoom.click(); + await expect(async () => { + if (await zhbPage.locator('.close > .iconfont').first().isVisible()) { + await zhbPage.locator('.close > .iconfont').first().click(); + } + await zhbPage.getByRole('button', { name: '选择顾客' }).click(); + await expect(zhbPage.locator('#page_searchMember').getByText('创建会员')).toBeVisible(); + }).toPass(); + await zhbPage + .getByRole('textbox', { name: '输入会员手机号或姓名或卡号搜索' }) + .fill(customer.phone, { delay: 100 }); + await zhbPage.locator('#page_searchMember svg').click(); + + const $customerTr = zhbPage + .locator('.list-warp') + .filter({ has: zhbPage.locator('.name', { hasText: customer.name }) }); + await $customerTr.locator('.list-body').first().click(); + + await zhbPage.getByText('项目开单').click(); + await expect(zhbPage.locator('#page_roomDetail').getByText('服务项目')).toBeVisible(); + await zhbPage.getByText('选择', { exact: true }).nth(1).click(); + await expect(zhbPage.locator('#serviceSelector').getByText('项目选择')).toBeVisible(); + await zhbPage.locator('.goods-content-item').nth(faker.number.int(30)).click(); + await zhbPage.locator('#serviceSelector').getByText('确认').click(); + await zhbPage + .locator('div') + .filter({ hasText: /^明星足浴$/ }) + .locator('span') + .first() + .click(); + await zhbPage.getByRole('button', { name: '完成开单' }).click(); + 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/); + await zhbPage + .locator('#page_footBathPay span') + .filter({ hasText: /结\s算/ }) + .click(); + await expect(zhbPage.getByText('顾客满意度点评')).toBeVisible({ timeout: 2000 }); + }).toPass(); + + await zhbPage.getByText('不想评价').click(); + await expect(zhbPage.locator('#page_footBathPay').getByText('立即返回')).not.toBeVisible(); + }); + + await test.step('起钟下钟,清理房间', async () => { + const $cleanRoom = $$room.filter({ + has: zhbPage.locator('.roomName', { hasText: new RegExp(`^${useRoomName}$`) }), + }); + await expect($cleanRoom).toContainText('已结清'); + await $cleanRoom.click(); + await zhbPage.getByText('技师操作').click(); + await zhbPage.getByText('起钟', { exact: true }).click(); + await zhbPage.getByText('起钟成功!').click(); + await zhbPage.getByText('技师操作').click(); + await zhbPage.getByText('下钟', { exact: true }).click(); + await zhbPage + .locator('div') + .filter({ hasText: /^确认返回$/ }) + .locator('div') + .first() + .click(); + await zhbPage.getByRole('button', { name: '不需要' }).click(); + + await expect($cleanRoom).toContainText('打扫'); + await $cleanRoom.click(); + await zhbPage + .locator('div') + .filter({ hasText: /^确定取消$/ }) + .locator('div') + .first() + .click(); + await expect($cleanRoom).toContainText('空房'); + }); }); -}); +} -test('h5 demo', async ({ - zhbAdminPage, +test.skip('h5 demo', async ({ + zhbAdminPage, // zhbPage, h5Page, h5LoginPage, diff --git a/tests/zhb/pom/customerPage.js b/tests/zhb/pom/customerPage.js index c3174bb..04ef87a 100644 --- a/tests/zhb/pom/customerPage.js +++ b/tests/zhb/pom/customerPage.js @@ -4,7 +4,7 @@ const { expect } = require('@playwright/test'); export class Customer { constructor({ name = faker.person.fullName(), - phone = faker.helpers.fromRegExp(/123[0-1]{8}/), + phone = faker.helpers.fromRegExp(/123[0-5]{8}/), } = {}) { this.name = name; this.phone = phone;