|
1 | | -import { type PlaywrightTestConfig, devices } from "@playwright/test"; |
2 | | -import path from "path"; |
| 1 | +import { defineConfig, devices } from "@playwright/test"; |
3 | 2 |
|
4 | | -// Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port |
5 | | -const baseURL = |
6 | | - process.env.BASE_URL || `http://localhost:${process.env.PORT || 3000}`; |
7 | | - |
8 | | -// Reference: https://playwright.dev/docs/test-configuration |
9 | | -const config: PlaywrightTestConfig = { |
10 | | - // Timeout per test |
11 | | - timeout: 30 * 1000, |
12 | | - // Test directory |
13 | | - testDir: path.join(__dirname, "e2e"), |
14 | | - // If a test fails, retry it additional 2 times |
15 | | - retries: 2, |
16 | | - // Artifacts folder where screenshots, videos, and traces are stored. |
17 | | - outputDir: "e2e-results/", |
18 | | - |
19 | | - // Run your local dev server before starting the tests: |
20 | | - // https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests |
21 | | - webServer: { |
22 | | - command: "npm run dev", |
23 | | - url: baseURL, |
24 | | - timeout: 120 * 1000, |
25 | | - reuseExistingServer: !!process.env.CI, |
26 | | - }, |
| 3 | +/** |
| 4 | + * Read environment variables from file. |
| 5 | + * https://github.com/motdotla/dotenv |
| 6 | + */ |
| 7 | +// require('dotenv').config(); |
27 | 8 |
|
| 9 | +/** |
| 10 | + * See https://playwright.dev/docs/test-configuration. |
| 11 | + */ |
| 12 | +export default defineConfig({ |
| 13 | + testDir: "./e2e", |
| 14 | + /* Run tests in files in parallel */ |
| 15 | + fullyParallel: true, |
| 16 | + /* Fail the build on CI if you accidentally left test.only in the source code. */ |
| 17 | + forbidOnly: !!process.env.CI, |
| 18 | + /* Retry on CI only */ |
| 19 | + retries: process.env.CI ? 2 : 0, |
| 20 | + /* Opt out of parallel tests on CI. */ |
| 21 | + workers: process.env.CI ? 1 : undefined, |
| 22 | + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ |
| 23 | + reporter: "html", |
| 24 | + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ |
28 | 25 | use: { |
29 | | - // Use baseURL so to make navigations relative. |
30 | | - // More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url |
31 | | - baseURL, |
32 | | - |
33 | | - headless: true, |
34 | | - |
35 | | - // Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc. |
36 | | - // More information: https://playwright.dev/docs/trace-viewer |
37 | | - trace: "retry-with-trace", |
| 26 | + /* Base URL to use in actions like `await page.goto('/')`. */ |
| 27 | + // baseURL: 'http://127.0.0.1:3000', |
38 | 28 |
|
39 | | - // All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context |
40 | | - // contextOptions: { |
41 | | - // ignoreHTTPSErrors: true, |
42 | | - // }, |
| 29 | + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ |
| 30 | + trace: "on-first-retry", |
43 | 31 | }, |
44 | 32 |
|
| 33 | + /* Configure projects for major browsers */ |
45 | 34 | projects: [ |
46 | 35 | { |
47 | | - name: "Desktop Chrome", |
48 | | - use: { |
49 | | - ...devices["Desktop Chrome"], |
50 | | - }, |
| 36 | + name: "chromium", |
| 37 | + use: { ...devices["Desktop Chrome"] }, |
| 38 | + }, |
| 39 | + |
| 40 | + { |
| 41 | + name: "firefox", |
| 42 | + use: { ...devices["Desktop Firefox"] }, |
51 | 43 | }, |
| 44 | + |
| 45 | + { |
| 46 | + name: "webkit", |
| 47 | + use: { ...devices["Desktop Safari"] }, |
| 48 | + }, |
| 49 | + |
| 50 | + /* Test against mobile viewports. */ |
52 | 51 | // { |
53 | | - // name: 'Desktop Firefox', |
54 | | - // use: { |
55 | | - // ...devices['Desktop Firefox'], |
56 | | - // }, |
| 52 | + // name: 'Mobile Chrome', |
| 53 | + // use: { ...devices['Pixel 5'] }, |
57 | 54 | // }, |
58 | 55 | // { |
59 | | - // name: 'Desktop Safari', |
60 | | - // use: { |
61 | | - // ...devices['Desktop Safari'], |
62 | | - // }, |
| 56 | + // name: 'Mobile Safari', |
| 57 | + // use: { ...devices['iPhone 12'] }, |
63 | 58 | // }, |
64 | | - // Test against mobile viewports. |
65 | | - { |
66 | | - name: "Mobile Chrome", |
67 | | - use: { |
68 | | - ...devices["Pixel 5"], |
69 | | - }, |
70 | | - }, |
| 59 | + |
| 60 | + /* Test against branded browsers. */ |
71 | 61 | // { |
72 | | - // name: 'Mobile Safari', |
73 | | - // use: devices['iPhone 12'], |
| 62 | + // name: 'Microsoft Edge', |
| 63 | + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, |
| 64 | + // }, |
| 65 | + // { |
| 66 | + // name: 'Google Chrome', |
| 67 | + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, |
74 | 68 | // }, |
75 | 69 | ], |
76 | 70 |
|
77 | | - reporter: [["html", { outputFolder: "e2e-report" }]], |
78 | | -}; |
79 | | -export default config; |
| 71 | + /* Run your local dev server before starting the tests */ |
| 72 | + webServer: { |
| 73 | + command: "npm run dev", |
| 74 | + url: "http://127.0.0.1:3000", |
| 75 | + reuseExistingServer: !process.env.CI, |
| 76 | + }, |
| 77 | +}); |
0 commit comments