|
1 | 1 | import { defineConfig, devices } from '@playwright/test';
|
2 |
| - |
3 | 2 | import { config } from 'dotenv';
|
| 3 | +import path from 'path'; |
| 4 | + |
4 | 5 | config();
|
5 | 6 |
|
| 7 | +/* === Run your local dev server before starting the tests === */ |
| 8 | + |
6 | 9 | /**
|
7 | 10 | * See https://playwright.dev/docs/test-configuration.
|
8 |
| - * See https://playwright.dev/docs/trace-viewer to Collect trace when retrying the failed test |
9 | 11 | */
|
10 | 12 | export default defineConfig({
|
11 |
| - testDir: 'e2e', |
12 |
| - /* Run tests in files in parallel */ |
13 |
| - fullyParallel: true, |
14 |
| - reporter: 'html', |
15 |
| - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ |
| 13 | + testDir: '.', |
| 14 | + outputDir: 'run_results/', // directory for screenshots and videos |
| 15 | + snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}', // just in case, do not delete it |
| 16 | + fullyParallel: true, // false only for specific tests, overwritten in specific projects or global setups of projects |
| 17 | + forbidOnly: !!process.env.CI, |
| 18 | + retries: process.env.CI ? 2 : 0, |
| 19 | + workers: process.env.CI ? 1 : undefined, // undefined = amount of projects * amount of tests |
| 20 | + timeout: 30 * 1000, // timeout can be changed |
16 | 21 | use: {
|
17 |
| - /* Base URL to use in actions like `await page.goto('/')`. */ |
18 |
| - baseURL: process.env.FRONTEND_BASE_URL ?? 'http://localhost:3001', |
| 22 | + baseURL: process.env.CI |
| 23 | + ? process.env.CI_DEFAULT_BASE_URL |
| 24 | + : (process.env.FRONTEND_BASE_URL ?? 'http://localhost:3001'), |
| 25 | + trace: 'retain-on-failure', // trace takes EVERYTHING from page source, records every single step, should be used only when normal debugging won't work |
| 26 | + screenshot: 'on', // either 'on' here or in different method in modules, if 'on' all screenshots are overwritten each time the test is run |
| 27 | + headless: true, // instead of changing it to false, run 'yarn test:e2e:debug' or 'yarn test:e2e:ui' |
| 28 | + testIdAttribute: 'data-testid', // taken from Twenty source |
| 29 | + viewport: { width: 1920, height: 1080 }, // most laptops use this resolution |
| 30 | + launchOptions: { |
| 31 | + slowMo: 500, // time in milliseconds between each step, better to use it than explicitly define timeout in tests |
| 32 | + }, |
19 | 33 | },
|
20 |
| - |
21 |
| - /* Configure projects for major browsers */ |
| 34 | + expect: { |
| 35 | + timeout: 5000, |
| 36 | + }, |
| 37 | + reporter: [['html', { open: 'never' }]], |
22 | 38 | projects: [
|
| 39 | + { |
| 40 | + name: 'Login setup', |
| 41 | + testMatch: /login\.setup\.ts/, // finds all tests matching this regex, in this case only 1 test should be found |
| 42 | + }, |
23 | 43 | {
|
24 | 44 | name: 'chromium',
|
25 |
| - use: { ...devices['Desktop Chrome'] }, |
| 45 | + use: { |
| 46 | + ...devices['Desktop Chrome'], |
| 47 | + storageState: path.resolve(__dirname, '.auth', 'user.json'), // takes saved cookies from directory |
| 48 | + }, |
| 49 | + dependencies: ['Login setup'], // forces to run login setup before running tests from this project - CASE SENSITIVE |
26 | 50 | },
|
27 |
| - |
28 | 51 | {
|
29 | 52 | name: 'firefox',
|
30 |
| - use: { ...devices['Desktop Firefox'] }, |
| 53 | + use: { |
| 54 | + ...devices['Desktop Firefox'], |
| 55 | + storageState: path.resolve(__dirname, '.auth', 'user.json'), |
| 56 | + }, |
| 57 | + dependencies: ['Login setup'], |
31 | 58 | },
|
32 | 59 |
|
33 |
| - { |
34 |
| - name: 'webkit', |
35 |
| - use: { ...devices['Desktop Safari'] }, |
36 |
| - }, |
| 60 | + //{ |
| 61 | + // name: 'webkit', |
| 62 | + // use: { ...devices['Desktop Safari'] }, |
| 63 | + //}, |
37 | 64 |
|
38 |
| - { |
39 |
| - name: 'Google Chrome', |
40 |
| - use: { ...devices['Desktop Chrome'], channel: 'chrome' }, |
41 |
| - }, |
| 65 | + /* Test against mobile viewports. */ |
| 66 | + // { |
| 67 | + // name: 'Mobile Chrome', |
| 68 | + // use: { ...devices['Pixel 5'] }, |
| 69 | + // }, |
| 70 | + // { |
| 71 | + // name: 'Mobile Safari', |
| 72 | + // use: { ...devices['iPhone 12'] }, |
| 73 | + // }, |
| 74 | + |
| 75 | + /* Test against branded browsers. */ |
| 76 | + //{ |
| 77 | + // name: 'Microsoft Edge', |
| 78 | + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, |
| 79 | + //}, |
| 80 | + //{ |
| 81 | + // name: 'Google Chrome', |
| 82 | + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, |
| 83 | + //}, |
42 | 84 | ],
|
43 | 85 | });
|
0 commit comments