const { test: base, expect, devices } = require('@playwright/test'); const zhbAuthFile = '.auth/zhb.json'; const zhbAdminAuthFile = '.auth/zhb_admin.json'; const test = base.extend({ /** * @type {import('@playwright/test').Page} */ zhbPage: async ({ browser, baseURL }, use) => { const context = await browser.newContext({ storageState: zhbAuthFile, }); const page = await context.newPage(); await page.goto(baseURL); console.log(baseURL); await use(page); await page.close(); await context.close(); }, /** * @type {import('@playwright/test').Page} */ zhbAdminPage: async ({ browser }, use) => { const baseURL = process.env.ZHB_ADMIN_URL; const account = process.env.ZHB_ACCOUNT; const password = process.env.ZHB_PASSWORD; const context = await browser.newContext({ storageState: zhbAdminAuthFile, }); const page = await context.newPage(); await page.goto(baseURL); console.log(baseURL); await page.getByPlaceholder('账户').fill(account); await page.getByPlaceholder('密码').fill(password); await page.getByRole('button', { name: '登 录' }).click(); await expect(page.locator('a').filter({ hasText: /^收银$/ })).toBeVisible(); await use(page); await page.close(); await context.close(); }, /** * @type {import('@playwright/test').Page} */ h5Page: async ({ browser }, use) => { const baseURL = process.env.ZHB_H5_URL; const iPhone = devices['iPhone 14']; const context = await browser.newContext({ ...iPhone, storageState: undefined, hasTouch: true, isMobile: true, // 设置为移动设备 viewport: iPhone.viewport, // 使用 iPhone 的视口配置 }); const page = await context.newPage(); await page.goto(baseURL); await use(page); }, }); module.exports = { test, expect, };