-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
102 lines (94 loc) · 2.81 KB
/
playwright.config.ts
File metadata and controls
102 lines (94 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* eslint-disable no-console */
import { chromium, defineConfig, devices, PlaywrightTestConfig } from '@playwright/test';
import dotenv from 'dotenv';
import fs from 'fs';
import path from 'path';
// Load environment variables from .env (quietly if missing)
dotenv.config({ path: path.resolve(__dirname, '.env'), quiet: true });
// Determine base URL
const TEST_BASE_URL = process.env.TEST_BASE_URL;
const EXTERNAL_IP = process.env.EXTERNAL_IP;
let BASE_URL: string;
if (TEST_BASE_URL) {
BASE_URL = TEST_BASE_URL;
} else if (EXTERNAL_IP) {
BASE_URL = `https://${EXTERNAL_IP}.nip.io`;
console.warn(`⚠️ TEST_BASE_URL not defined, using EXTERNAL_IP fallback: ${BASE_URL}`);
} else {
BASE_URL = 'http://localhost';
console.warn('⚠️ Neither TEST_BASE_URL nor EXTERNAL_IP defined, using default: http://localhost');
}
// Prepare results directory
const RESULTS_DIR = path.resolve(__dirname, 'playwright-report');
fs.mkdirSync(RESULTS_DIR, { recursive: true });
// Define browsers
const BROWSERS = [
{
name: 'chromium',
label: 'chrome',
device: devices['Desktop Chrome'],
browserType: chromium
}
// {
// name: 'firefox',
// label: 'firefox',
// device: devices['Desktop Firefox'],
// browserType: firefox
// },
// {
// name: 'webkit',
// label: 'safari',
// device: devices['Desktop Safari'],
// browserType: webkit
// }
] as const;
// Base use configuration
const baseUseConfig: PlaywrightTestConfig['use'] = {
baseURL: BASE_URL,
headless: true,
ignoreHTTPSErrors: true,
viewport: { width: 1920, height: 1080 },
screenshot: process.env.CI ? 'only-on-failure' : 'on',
trace: process.env.CI ? 'retain-on-failure' : 'on',
video: process.env.CI ? 'retain-on-failure' : 'on'
};
// Export Playwright configuration
export default defineConfig({
forbidOnly: !!process.env.CI,
fullyParallel: true,
globalTeardown: path.resolve(__dirname, './src/e2e/shared/teardown.ts'),
outputDir: `${RESULTS_DIR}/results`,
reporter: [
['list'],
['html', { open: 'always', outputFolder: `${RESULTS_DIR}/html-report` }],
['junit', { outputFile: `${RESULTS_DIR}/junit-results.xml` }]
],
retries: process.env.CI ? 1 : 0,
testDir: './src/e2e',
testMatch: /.*\.spec\.tsx?$/,
timeout: 120_000,
use: baseUseConfig,
workers: process.env.CI ? 1 : 4,
projects: BROWSERS.flatMap(({ name, device }) => [
// Setup project (for authentication, etc.)
{
name: `${name}-setup`,
use: {
...device,
...baseUseConfig
},
testDir: path.resolve(__dirname, './src/e2e'),
testMatch: /setup\.ts$/
},
// Main test projects
{
name,
use: {
...device,
...baseUseConfig,
storageState: path.join(RESULTS_DIR, `${name}-admin-session.json`)
},
dependencies: [`${name}-setup`]
}
])
});