Files
novalon-manage-system/novalon-manage-web/playwright.config.ts
T
张翔 76d8afa264 feat: 配置环境变量和Playwright配置
- 创建 .env.test 测试环境配置文件
- 更新 playwright.config.ts 添加角色测试项目
- 配置测试用户密码为 Test@123
- 添加独立的角色测试项目配置
2026-04-04 20:57:27 +08:00

126 lines
3.2 KiB
TypeScript

import { defineConfig, devices } from '@playwright/test';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const isHeadless = process.env.PLAYWRIGHT_HEADLESS === 'true' || process.env.CI === 'true';
const baseURL = process.env.TEST_BASE_URL || process.env.VITE_BASE_URL || 'http://localhost:3002';
export default defineConfig({
testDir: './e2e',
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 1,
workers: 1,
reporter: [
['html', { outputFolder: 'playwright-report' }],
['json', { outputFile: 'test-results/results.json' }],
['junit', { outputFile: 'test-results/junit.xml' }],
['list'],
['./e2e/customReporter.ts']
],
timeout: 120000,
expect: {
timeout: 30000,
toHaveScreenshot: { threshold: 0.2 },
toMatchSnapshot: { threshold: 0.2 }
},
use: {
baseURL: baseURL,
trace: process.env.CI ? 'retain-on-failure' : 'on-first-retry',
screenshot: 'only-on-failure',
video: process.env.CI ? 'retain-on-failure' : 'on-first-retry',
actionTimeout: 30000,
navigationTimeout: 60000,
headless: isHeadless,
locale: 'zh-CN',
timezoneId: 'Asia/Shanghai',
ignoreHTTPSErrors: true,
bypassCSP: true,
viewport: { width: 1280, height: 720 },
launchOptions: {
slowMo: process.env.CI ? 0 : 100
},
contextOptions: {
permissions: ['geolocation'],
geolocation: { latitude: 35.6895, longitude: 139.6917 },
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
},
projects: [
{
name: 'role-based-tests',
testDir: './e2e/role-based-tests/scenarios',
testMatch: /.*\.spec\.ts/,
use: {
...devices['Desktop Chrome'],
launchOptions: {
args: [
'--disable-blink-features=AutomationControlled',
'--disable-dev-shm-usage',
'--no-sandbox'
]
}
},
},
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
launchOptions: {
args: [
'--disable-blink-features=AutomationControlled',
'--disable-dev-shm-usage',
'--no-sandbox'
]
}
},
},
{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
launchOptions: {
firefoxUserPrefs: {
'dom.webdriver.enabled': false,
'useAutomationExtension': false
}
}
},
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
{
name: 'Mobile Chrome',
use: {
...devices['Pixel 5'],
launchOptions: {
args: [
'--disable-blink-features=AutomationControlled',
'--disable-dev-shm-usage'
]
}
},
},
],
webServer: {
command: 'npm run dev',
url: 'http://localhost:3002',
reuseExistingServer: !process.env.CI,
timeout: 120000,
stdout: 'pipe',
stderr: 'pipe'
},
globalSetup: path.resolve(__dirname, './e2e/global-setup.ts'),
globalTeardown: path.resolve(__dirname, './e2e/global-teardown.ts'),
});