更新 Playwright 配置以调整超时设置,新增简单测试命令,并重构测试用例以提高可读性
This commit is contained in:
parent
be91605c3c
commit
5247b50c0c
@ -7,6 +7,7 @@
|
|||||||
"mgj_codegen": "npx playwright codegen https://vip1.meiguanjia.net/shair/?v=mgj",
|
"mgj_codegen": "npx playwright codegen https://vip1.meiguanjia.net/shair/?v=mgj",
|
||||||
"zhb_codegen": "npx playwright codegen https://shengyibao.meiguanjia.net/young/",
|
"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: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",
|
"ui": "npx playwright test --ui",
|
||||||
"pwi": "npm ci && npx playwright install",
|
"pwi": "npm ci && npx playwright install",
|
||||||
"pwu": "npx playwright install --with-deps"
|
"pwu": "npx playwright install --with-deps"
|
||||||
|
|||||||
@ -30,7 +30,7 @@ module.exports = defineConfig({
|
|||||||
/* 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. */
|
||||||
timeout: 5 * 60000,
|
timeout: 3 * 60000,
|
||||||
expect: {
|
expect: {
|
||||||
toPass: {
|
toPass: {
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
|
|||||||
@ -9,11 +9,8 @@ test.describe
|
|||||||
console.log(`${customer.phone}-${customer.username}`);
|
console.log(`${customer.phone}-${customer.username}`);
|
||||||
|
|
||||||
test('登录touch和h5,创建顾客购买会员卡', async ({ touchPage, touchCustomerPage }) => {
|
test('登录touch和h5,创建顾客购买会员卡', async ({ touchPage, touchCustomerPage }) => {
|
||||||
await test.step('创建顾客', async () => {
|
|
||||||
await touchCustomerPage.createCustomer(customer);
|
|
||||||
});
|
|
||||||
|
|
||||||
await test.step('在touch页面购买会员卡', async () => {
|
await test.step('在touch页面购买会员卡', async () => {
|
||||||
|
await touchCustomerPage.createCustomer(customer);
|
||||||
await touchPage.getByText('去开单').click();
|
await touchPage.getByText('去开单').click();
|
||||||
await touchPage.locator('.more > .icon > svg').click();
|
await touchPage.locator('.more > .icon > svg').click();
|
||||||
await touchPage.getByText('去开卡').click();
|
await touchPage.getByText('去开卡').click();
|
||||||
@ -29,7 +26,7 @@ test.describe
|
|||||||
.nth(3)
|
.nth(3)
|
||||||
.click();
|
.click();
|
||||||
await touchPage.locator('.paymentInfoItem', { hasText: '现金' }).click();
|
await touchPage.locator('.paymentInfoItem', { hasText: '现金' }).click();
|
||||||
await touchPage.getByText('推送消费提醒').click();
|
await touchPage.getByLabel('推送消费提醒').uncheck();
|
||||||
await touchPage.getByLabel('结算签字').uncheck();
|
await touchPage.getByLabel('结算签字').uncheck();
|
||||||
await touchPage.getByRole('button', { name: /结\s算/ }).click();
|
await touchPage.getByRole('button', { name: /结\s算/ }).click();
|
||||||
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 h5Page.locator('.bar_item', { hasText: '商城' }).click();
|
||||||
await expect(h5Page.locator('.title', { hasText: '商城' })).toBeVisible();
|
await expect(h5Page.locator('.title', { hasText: '商城' })).toBeVisible();
|
||||||
await h5Page.locator('.li span', { hasText: '全部' }).click();
|
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.getByText('立即购买').click();
|
||||||
await h5Page.locator('uni-text').filter({ hasText: '佘山二店' }).click();
|
|
||||||
await h5Page.getByText('确认').click();
|
await h5Page.getByText('确认').click();
|
||||||
await h5Page.getByText('哎哟代理卡').click();
|
await h5Page.getByText('哎哟代理卡').click();
|
||||||
await expect(h5Page.getByText('确认支付')).toBeEnabled();
|
|
||||||
await h5Page.getByText('确认支付').click();
|
await h5Page.getByText('确认支付').click();
|
||||||
await expect(h5Page.getByText('支付成功').first()).toBeVisible();
|
await expect(h5Page.getByText('支付成功').first()).toBeVisible();
|
||||||
await expect(h5Page.getByText('查看订单')).toBeVisible();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,17 +5,18 @@ 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');
|
||||||
|
|
||||||
|
/**@type {{name: string, phone: string}[]} */
|
||||||
const records = parse(fs.readFileSync(path.join(__dirname, 'zhb.csv')), {
|
const records = parse(fs.readFileSync(path.join(__dirname, 'zhb.csv')), {
|
||||||
columns: true,
|
columns: true,
|
||||||
skip_empty_lines: true,
|
skip_empty_lines: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
test('csv', async ({ zhbPage }, workerInfo) => {
|
test('csv', async ({ zhbPage }) => {
|
||||||
console.log(records.length);
|
console.log(records.length);
|
||||||
const $area = zhbPage
|
const $$emptyRoom = zhbPage
|
||||||
.locator('.area')
|
.locator('.area')
|
||||||
.filter({ has: zhbPage.locator('.area-name', { hasText: '二楼' }) });
|
.locator('.room-list .room')
|
||||||
const $$room = $area.locator('.room-list .room');
|
.filter({ has: zhbPage.getByText('空房') });
|
||||||
|
|
||||||
// 随机csv文件中的任意一个顾客
|
// 随机csv文件中的任意一个顾客
|
||||||
const record = records[faker.number.int({ min: 0, max: records.length - 1 })];
|
const record = records[faker.number.int({ min: 0, max: records.length - 1 })];
|
||||||
@ -27,12 +28,9 @@ test('csv', async ({ zhbPage }, workerInfo) => {
|
|||||||
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
|
await $$emptyRoom.first().waitFor();
|
||||||
.filter({ has: zhbPage.getByText('空房') })
|
useRoomName = await $$emptyRoom.first().locator('.roomName').innerText();
|
||||||
.nth(workerInfo.workerIndex % 3);
|
await $$emptyRoom.first().click();
|
||||||
await $emptyRoom.locator('.roomName').waitFor();
|
|
||||||
useRoomName = await $emptyRoom.locator('.roomName').innerText();
|
|
||||||
await $emptyRoom.click();
|
|
||||||
await expect(async () => {
|
await expect(async () => {
|
||||||
if (await zhbPage.locator('.close > .iconfont').first().isVisible()) {
|
if (await zhbPage.locator('.close > .iconfont').first().isVisible()) {
|
||||||
await zhbPage.locator('.close > .iconfont').first().click();
|
await zhbPage.locator('.close > .iconfont').first().click();
|
||||||
@ -56,7 +54,7 @@ test('csv', async ({ zhbPage }, workerInfo) => {
|
|||||||
await expect(zhbPage.locator('#serviceSelector').getByText('项目选择')).toBeVisible();
|
await expect(zhbPage.locator('#serviceSelector').getByText('项目选择')).toBeVisible();
|
||||||
await zhbPage
|
await zhbPage
|
||||||
.locator('.goods-content-item')
|
.locator('.goods-content-item')
|
||||||
.nth(faker.number.int({ min: 0, max: 14 }))
|
.nth(faker.number.int({ min: 0, max: 10 }))
|
||||||
.click();
|
.click();
|
||||||
await zhbPage.locator('#serviceSelector').getByText('确认').click();
|
await zhbPage.locator('#serviceSelector').getByText('确认').click();
|
||||||
await zhbPage
|
await zhbPage
|
||||||
@ -83,13 +81,14 @@ test('csv', async ({ zhbPage }, workerInfo) => {
|
|||||||
.locator('#page_footBathPay span')
|
.locator('#page_footBathPay span')
|
||||||
.filter({ hasText: /结\s算/ })
|
.filter({ hasText: /结\s算/ })
|
||||||
.click();
|
.click();
|
||||||
await expect(zhbPage.getByText('顾客满意度点评')).toBeVisible({ timeout: 2000 });
|
await expect(zhbPage.getByText('顾客满意度点评')).toBeVisible();
|
||||||
|
|
||||||
await zhbPage.getByText('不想评价').click();
|
await zhbPage.getByText('不想评价').click();
|
||||||
await zhbPage.locator('#page_footBathPay').getByText('立即返回').click();
|
await zhbPage.locator('#page_footBathPay').getByText('立即返回').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
await test.step('起钟下钟,清理房间', async () => {
|
await test.step('起钟下钟,清理房间', async () => {
|
||||||
|
const $$room = zhbPage.locator('.area').locator('.room-list .room');
|
||||||
const $cleanRoom = $$room.filter({
|
const $cleanRoom = $$room.filter({
|
||||||
has: zhbPage.locator('.roomName', { hasText: new RegExp(`^${useRoomName}$`) }),
|
has: zhbPage.locator('.roomName', { hasText: new RegExp(`^${useRoomName}$`) }),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user