playwright/playwright.config.js
2025-03-07 13:50:01 +08:00

65 lines
1.7 KiB
JavaScript

// @ts-check
const {defineConfig, devices} = require('@playwright/test');
/**
* @see https://playwright.dev/docs/test-configuration
*/
/**
* @type {import('@playwright/test').PlaywrightTestConfig}
*/
const config = {
testDir: './tests',
/* 测试超时时间 */
timeout: parseInt(process.env.EXPECT_TIMEOUT),
/* 每个测试的预期状态 */
expect: {
timeout: parseInt(process.env.EXPECT_TIMEOUT)
},
/* 测试运行并发数 */
fullyParallel: false,
forbidOnly: !!process.env.CI,
/* 失败重试次数 */
retries: process.env.CI ? 2 : 0,
workers: 1,
/* 测试报告相关 */
reporter: 'html',
/* 共享设置 */
use: {
/* 基础URL */
baseURL: process.env.BASE_URL,
/* 收集测试追踪信息 */
trace: 'on-first-retry',
/* 自动截图 */
screenshot: 'only-on-failure',
/* 录制视频 */
video: 'retain-on-failure',
/* 浏览器配置 */
headless: process.env.BROWSER_HEADLESS === 'true',
viewport: {
width: parseInt(process.env.VIEWPORT_WIDTH),
height: parseInt(process.env.VIEWPORT_HEIGHT)
},
/* 浏览器启动选项 */
launchOptions: {
slowMo: parseInt(process.env.BROWSER_SLOW_MO),
timeout: parseInt(process.env.BROWSER_TIMEOUT)
}
},
/* 配置不同的浏览器项目 */
projects: [
{
name: 'chromium',
use: {...devices['Desktop Chrome']},
},
],
/* 本地开发服务器配置 */
// webServer: {
// command: 'npm run start',
// port: 3000,
// reuseExistingServer: !process.env.CI,
// },
};
module.exports = config;