This commit is contained in:
wenpeng 2024-11-07 20:35:26 +08:00 committed by LingandRX
parent e7edca3acc
commit b0283aca9a
3 changed files with 102 additions and 96 deletions

View File

@ -26,7 +26,7 @@ module.exports = defineConfig({
/* Retry on CI only */ /* Retry on CI only */
retries: process.env.CI ? 2 : 0, retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */ /* 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 to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html', reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */

View File

@ -1,7 +1,9 @@
const { faker } = require('@faker-js/faker');
const { test, expect } = require('./fixture/common'); const { test, expect } = require('./fixture/common');
const { Customer } = require('./pom/customerPage'); const { Customer } = require('./pom/customerPage');
test('demo', async ({ zhbPage, customerPage }) => { for (let i = 0; i < 50; i++) {
test(`demo${i}`, async ({ zhbPage, customerPage }, workerInfo) => {
const $area = zhbPage const $area = zhbPage
.locator('.area') .locator('.area')
.filter({ has: zhbPage.locator('.area-name', { hasText: '二楼' }) }); .filter({ has: zhbPage.locator('.area-name', { hasText: '二楼' }) });
@ -16,11 +18,14 @@ test('demo', async ({ zhbPage, customerPage }) => {
let useRoomName; let useRoomName;
await test.step('购买商品', async () => { await test.step('购买商品', async () => {
await zhbPage.locator('#tab_main li').filter({ hasText: '营业' }).click(); await zhbPage.locator('#tab_main li').filter({ hasText: '营业' }).click();
const $emptyRoom = $$room.filter({ has: zhbPage.getByText('空房') }).first(); const $emptyRoom = $$room.filter({ has: zhbPage.getByText('空房') }).nth(workerInfo.workerIndex % 3);
useRoomName = await $emptyRoom.locator('.roomName').innerText(); useRoomName = await $emptyRoom.locator('.roomName').innerText();
expect(useRoomName).not.toBeNull(); expect(useRoomName).not.toBeNull();
await $emptyRoom.click(); await $emptyRoom.click();
await expect(async () => { 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 zhbPage.getByRole('button', { name: '选择顾客' }).click();
await expect(zhbPage.locator('#page_searchMember').getByText('创建会员')).toBeVisible(); await expect(zhbPage.locator('#page_searchMember').getByText('创建会员')).toBeVisible();
}).toPass(); }).toPass();
@ -38,11 +43,11 @@ test('demo', async ({ zhbPage, customerPage }) => {
await expect(zhbPage.locator('#page_roomDetail').getByText('服务项目')).toBeVisible(); await expect(zhbPage.locator('#page_roomDetail').getByText('服务项目')).toBeVisible();
await zhbPage.getByText('选择', { exact: true }).nth(1).click(); await zhbPage.getByText('选择', { exact: true }).nth(1).click();
await expect(zhbPage.locator('#serviceSelector').getByText('项目选择')).toBeVisible(); await expect(zhbPage.locator('#serviceSelector').getByText('项目选择')).toBeVisible();
await zhbPage.getByText('臻品足疗 (10101)').click(); await zhbPage.locator('.goods-content-item').nth(faker.number.int(30)).click();
await zhbPage.locator('#serviceSelector').getByText('确认').click(); await zhbPage.locator('#serviceSelector').getByText('确认').click();
await zhbPage await zhbPage
.locator('div') .locator('div')
.filter({ hasText: /^星足浴$/ }) .filter({ hasText: /^星足浴$/ })
.locator('span') .locator('span')
.first() .first()
.click(); .click();
@ -53,9 +58,9 @@ test('demo', async ({ zhbPage, customerPage }) => {
await expect(async () => { await expect(async () => {
await zhbPage.locator('#page_footBathPay li').filter({ hasText: '现金' }).click(); await zhbPage.locator('#page_footBathPay li').filter({ hasText: '现金' }).click();
await expect(zhbPage.locator('#page_footBathPay li').filter({ hasText: '现金' })).toHaveClass( await expect(
/selected/ zhbPage.locator('#page_footBathPay li').filter({ hasText: '现金' })
); ).toHaveClass(/selected/);
await zhbPage await zhbPage
.locator('#page_footBathPay span') .locator('#page_footBathPay span')
.filter({ hasText: /结\s算/ }) .filter({ hasText: /结\s算/ })
@ -97,8 +102,9 @@ test('demo', async ({ zhbPage, customerPage }) => {
await expect($cleanRoom).toContainText('空房'); await expect($cleanRoom).toContainText('空房');
}); });
}); });
}
test('h5 demo', async ({ test.skip('h5 demo', async ({
zhbAdminPage, zhbAdminPage,
// zhbPage, // zhbPage,
h5Page, h5Page,

View File

@ -4,7 +4,7 @@ const { expect } = require('@playwright/test');
export class Customer { export class Customer {
constructor({ constructor({
name = faker.person.fullName(), name = faker.person.fullName(),
phone = faker.helpers.fromRegExp(/123[0-1]{8}/), phone = faker.helpers.fromRegExp(/123[0-5]{8}/),
} = {}) { } = {}) {
this.name = name; this.name = name;
this.phone = phone; this.phone = phone;