This repository has been archived on 2025-04-22. You can view files and clone it, but cannot push or open issues or pull requests.
playwright-demo/tests/fixtures/base.js
2024-10-15 22:17:14 +08:00

52 lines
1.3 KiB
JavaScript

const { test: base, expect, devices } = require('@playwright/test');
const path = require('path');
const authFile = path.resolve(__dirname, '../../.auth/admin.json');
const zhbAuthFile = path.join(__dirname, '../.auth/zhb_admin.json');
const test = base.extend({
/**
* @type {import('@playwright/test').Page}
*/
touchPage: async ({ browser, baseURL }, use) => {
const context = await browser.newContext({
storageState: authFile,
});
const page = await context.newPage();
await page.goto(baseURL);
await use(page);
await page.close();
await context.close();
},
/**
* @type {import('@playwright/test').Page}
*/
h5Page: async ({ browser }, use) => {
const iPhone = devices['iPhone 11'];
const context = await browser.newContext({
...iPhone,
storageState: undefined,
});
const page = await context.newPage();
await page.goto(process.env.H5_BASE_URL);
await use(page);
},
/**
* @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);
await use(page);
await page.close();
await context.close();
},
});
module.exports = {
test,
expect,
};