|
1 | | -/* |
2 | | - * Copyright (C) con terra GmbH |
3 | | - */ |
4 | 1 | import { |
5 | 2 | defineConfig, |
6 | 3 | devices, |
7 | 4 | PlaywrightTestConfig |
8 | 5 | } from "@playwright/test"; |
9 | | -import { env } from "process"; |
10 | 6 |
|
11 | | -/** |
12 | | - * See https://playwright.dev/docs/test-configuration. |
13 | | - */ |
14 | | -const baseURL = env.BASE_URL || "http://localhost:9090"; |
15 | | -const testDir = env.TESTS_DIR || "./src/test/end-to-end/test"; |
16 | | -const outputDir = env.TARGET_DIR || "./target/playwright/output"; |
| 7 | +// "CI" environment variable can be used to activate |
| 8 | +// specific settings for CI environments. |
| 9 | +const envCI = !!process.env.CI; |
17 | 10 |
|
18 | | -const isCI = !!env.CI; |
| 11 | +const isHeaded = process.argv.includes('--headed'); |
19 | 12 |
|
20 | | -const snapshotsFolder = env.SNAPSHOTS_DIR || "./src/test/end-to-end/test/snapshots/local"; |
| 13 | +// gpu is disabled for Chromium in headless mode |
| 14 | +// to ensure stability and performance |
| 15 | +// in environments where gpu acceleration is not supported |
| 16 | +const chromiumLaunchOptions = { |
| 17 | + args: isHeaded ? [] : ["--disable-gpu"] |
| 18 | +}; |
21 | 19 |
|
| 20 | +/** |
| 21 | + * See https://playwright.dev/docs/test-configuration. |
| 22 | + */ |
22 | 23 | const config: PlaywrightTestConfig = { |
23 | | - testDir, |
24 | | - outputDir: `${outputDir}/results`, |
25 | | - |
26 | | - snapshotPathTemplate: `${snapshotsFolder}/{testFileName}-snapshots/{arg}-{projectName}{ext}`, |
| 24 | + testDir: "./src/test/end-to-end", |
| 25 | + outputDir: "./target/end-to-end/results", |
| 26 | + snapshotDir: "./src/test/end-to-end/snapshots", |
27 | 27 |
|
28 | 28 | /* Run tests in files in parallel */ |
29 | 29 | fullyParallel: true, |
30 | | - /* Retry on CI only */ |
31 | | - retries: isCI ? 1 : 0, |
32 | 30 | /* Fail the build on CI if you accidentally left test.only in the source code. */ |
33 | | - forbidOnly: isCI, |
| 31 | + forbidOnly: envCI, |
| 32 | + /* Retry on CI only */ |
| 33 | + retries: envCI ? 2 : 0, |
34 | 34 | /* Opt out of parallel tests on CI. */ |
35 | | - workers: isCI ? 1 : 2, |
36 | | - |
37 | | - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ |
38 | | - use: { |
39 | | - /* Base URL to use in actions like `await page.goto('/')`. */ |
40 | | - baseURL, |
41 | | - |
42 | | - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ |
43 | | - trace: "on-first-retry" |
44 | | - }, |
45 | | - |
| 35 | + workers: envCI ? 1 : 2, |
46 | 36 | /* Reporter to use. See https://playwright.dev/docs/test-reporters */ |
47 | 37 | reporter: [ |
| 38 | + [ |
| 39 | + "list" |
| 40 | + ], |
48 | 41 | [ |
49 | 42 | "html", |
50 | 43 | { |
51 | | - outputFolder: `${outputDir}/reports/html`, |
52 | | - open: isCI ? "never" : "always" |
| 44 | + outputFolder: "./target/end-to-end/reports/html", |
| 45 | + open: envCI ? "never" : "on-failure" |
53 | 46 | } |
54 | | - ], |
55 | | - ["junit", { outputFile: `${outputDir}/reports/junit/results.xml` }] |
| 47 | + ] |
56 | 48 | ], |
57 | 49 |
|
58 | 50 | expect: { |
59 | 51 | toHaveScreenshot: { |
60 | | - maxDiffPixelRatio: 0.1, |
| 52 | + maxDiffPixelRatio: 0.01, |
61 | 53 | threshold: 0.05 |
62 | | - }, |
63 | | - // increased timeout (default is 5000) |
64 | | - // pro: less flaky tests, no need to wait for network state |
65 | | - // con: longer test duration where assertions are failing |
66 | | - timeout: 30000 |
| 54 | + } |
| 55 | + }, |
| 56 | + |
| 57 | + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ |
| 58 | + use: { |
| 59 | + /* Base URL to use in actions like `await page.goto('/')`. */ |
| 60 | + baseURL: "http://localhost:9090", |
| 61 | + |
| 62 | + /** |
| 63 | + * See https://playwright.dev/docs/trace-viewer |
| 64 | + * ci: Collect trace when retrying the failed test. |
| 65 | + * local: Collect trace for all tests. |
| 66 | + */ |
| 67 | + trace: envCI ? "on-first-retry": "on" |
67 | 68 | }, |
68 | 69 |
|
69 | | - /* Configure projects for major browsers */ |
70 | 70 | projects: [ |
71 | 71 | { |
72 | | - name: "Desktop Chrome", |
| 72 | + name: "Desktop Firefox", |
| 73 | + use: { |
| 74 | + ...devices["Desktop Firefox"] |
| 75 | + } |
| 76 | + }, |
| 77 | + { |
| 78 | + name: "Mobile Chrome", |
73 | 79 | use: { |
74 | | - ...devices["Desktop Chrome"], |
75 | | - launchOptions: { |
76 | | - // enable WEBGL for headless tests |
77 | | - args: isCI |
78 | | - ? ["--disable-gpu"] |
79 | | - : [] |
80 | | - }, |
81 | | - viewport: { width: 1920, height: 1080 } |
| 80 | + ...devices["Galaxy S9+"], |
| 81 | + launchOptions: chromiumLaunchOptions |
82 | 82 | } |
83 | 83 | } |
84 | | - ], |
85 | | - |
86 | | - timeout: isCI ? 120000 : 30000 |
| 84 | + ] |
87 | 85 | }; |
| 86 | + |
| 87 | + |
88 | 88 | export default defineConfig(config); |
0 commit comments