diff --git a/package.json b/package.json index f3ad260..9a8748a 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "mgj_codegen": "npx playwright codegen https://vip1.meiguanjia.net/shair/?v=mgj", "zhb_codegen": "npx playwright codegen https://shengyibao.meiguanjia.net/young/", "test:repeat": "npx playwright test ./tests/zhb ./tests/mgj ./tests/hlk --repeat-each=3", + "test:simple": "npx playwright test ./tests/zhb ./tests/mgj ./tests/hlk", "ui": "npx playwright test --ui", "pwi": "npm ci && npx playwright install", "pwu": "npx playwright install --with-deps" diff --git a/playwright.config.js b/playwright.config.js index 4ff0209..dc178c0 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -30,7 +30,7 @@ module.exports = defineConfig({ /* 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. */ - timeout: 5 * 60000, + timeout: 3 * 60000, expect: { toPass: { timeout: 30000, diff --git a/tests/hlk/demo.spec.js b/tests/hlk/demo.spec.js index c647c4b..c1f7574 100644 --- a/tests/hlk/demo.spec.js +++ b/tests/hlk/demo.spec.js @@ -9,11 +9,8 @@ test.describe console.log(`${customer.phone}-${customer.username}`); test('登录touch和h5,创建顾客购买会员卡', async ({ touchPage, touchCustomerPage }) => { - await test.step('创建顾客', async () => { - await touchCustomerPage.createCustomer(customer); - }); - await test.step('在touch页面购买会员卡', async () => { + await touchCustomerPage.createCustomer(customer); await touchPage.getByText('去开单').click(); await touchPage.locator('.more > .icon > svg').click(); await touchPage.getByText('去开卡').click(); @@ -29,7 +26,7 @@ test.describe .nth(3) .click(); await touchPage.locator('.paymentInfoItem', { hasText: '现金' }).click(); - await touchPage.getByText('推送消费提醒').click(); + await touchPage.getByLabel('推送消费提醒').uncheck(); await touchPage.getByLabel('结算签字').uncheck(); await touchPage.getByRole('button', { name: /结\s算/ }).click(); await touchPage.getByRole('button', { name: /跳\s过/ }).click(); @@ -44,14 +41,11 @@ test.describe await h5Page.locator('.bar_item', { hasText: '商城' }).click(); await expect(h5Page.locator('.title', { hasText: '商城' })).toBeVisible(); await h5Page.locator('.li span', { hasText: '全部' }).click(); - await h5Page.locator('.p-item').nth(2).click(); + await h5Page.locator('.p-item').filter({ hasText: '美肤' }).first().click(); await h5Page.getByText('立即购买').click(); - await h5Page.locator('uni-text').filter({ hasText: '佘山二店' }).click(); await h5Page.getByText('确认').click(); await h5Page.getByText('哎哟代理卡').click(); - await expect(h5Page.getByText('确认支付')).toBeEnabled(); await h5Page.getByText('确认支付').click(); await expect(h5Page.getByText('支付成功').first()).toBeVisible(); - await expect(h5Page.getByText('查看订单')).toBeVisible(); }); }); diff --git a/tests/zhb/csv-demo.spec.js b/tests/zhb/csv-demo.spec.js index 780d1c9..53e780b 100644 --- a/tests/zhb/csv-demo.spec.js +++ b/tests/zhb/csv-demo.spec.js @@ -5,17 +5,18 @@ const { faker } = require('@faker-js/faker'); const { test, expect } = require('./fixture/common'); const { Customer } = require('./pom/customerPage'); +/**@type {{name: string, phone: string}[]} */ const records = parse(fs.readFileSync(path.join(__dirname, 'zhb.csv')), { columns: true, skip_empty_lines: true, }); -test('csv', async ({ zhbPage }, workerInfo) => { +test('csv', async ({ zhbPage }) => { console.log(records.length); - const $area = zhbPage + const $$emptyRoom = zhbPage .locator('.area') - .filter({ has: zhbPage.locator('.area-name', { hasText: '二楼' }) }); - const $$room = $area.locator('.room-list .room'); + .locator('.room-list .room') + .filter({ has: zhbPage.getByText('空房') }); // 随机csv文件中的任意一个顾客 const record = records[faker.number.int({ min: 0, max: records.length - 1 })]; @@ -27,12 +28,9 @@ test('csv', async ({ zhbPage }, workerInfo) => { 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(); - await $emptyRoom.click(); + await $$emptyRoom.first().waitFor(); + useRoomName = await $$emptyRoom.first().locator('.roomName').innerText(); + await $$emptyRoom.first().click(); await expect(async () => { if (await zhbPage.locator('.close > .iconfont').first().isVisible()) { await zhbPage.locator('.close > .iconfont').first().click(); @@ -56,7 +54,7 @@ test('csv', async ({ zhbPage }, workerInfo) => { await expect(zhbPage.locator('#serviceSelector').getByText('项目选择')).toBeVisible(); await zhbPage .locator('.goods-content-item') - .nth(faker.number.int({ min: 0, max: 14 })) + .nth(faker.number.int({ min: 0, max: 10 })) .click(); await zhbPage.locator('#serviceSelector').getByText('确认').click(); await zhbPage @@ -83,13 +81,14 @@ test('csv', async ({ zhbPage }, workerInfo) => { .locator('#page_footBathPay span') .filter({ hasText: /结\s算/ }) .click(); - await expect(zhbPage.getByText('顾客满意度点评')).toBeVisible({ timeout: 2000 }); + await expect(zhbPage.getByText('顾客满意度点评')).toBeVisible(); await zhbPage.getByText('不想评价').click(); await zhbPage.locator('#page_footBathPay').getByText('立即返回').click(); }); await test.step('起钟下钟,清理房间', async () => { + const $$room = zhbPage.locator('.area').locator('.room-list .room'); const $cleanRoom = $$room.filter({ has: zhbPage.locator('.roomName', { hasText: new RegExp(`^${useRoomName}$`) }), });