|
1 | | -import { defineConfig, devices } from '@playwright/test'; |
2 | | - |
3 | 1 | /** |
4 | | - * Read environment variables from file. |
5 | | - * https://github.com/motdotla/dotenv |
| 2 | + * Root Playwright Configuration |
| 3 | + * |
| 4 | + * Delegates to the full test configuration in the Playwright submodule: |
| 5 | + * Tests/AngularNetTutorial-Playwright/ |
| 6 | + * |
| 7 | + * Running `npx playwright test` from the repo root uses this config, |
| 8 | + * which points testDir at the submodule's tests/ folder and imports |
| 9 | + * all shared settings (timeouts, viewports, reporters, projects) from |
| 10 | + * the submodule config. |
| 11 | + * |
| 12 | + * To run from the submodule directly (recommended for development): |
| 13 | + * cd Tests/AngularNetTutorial-Playwright |
| 14 | + * npx playwright test |
| 15 | + * |
| 16 | + * To run from the repo root (CI / convenience): |
| 17 | + * npx playwright test |
| 18 | + * npx playwright test --project=screenshots |
| 19 | + * npx playwright test --project=smoke |
6 | 20 | */ |
7 | | -// import dotenv from 'dotenv'; |
8 | | -// import path from 'path'; |
9 | | -// dotenv.config({ path: path.resolve(__dirname, '.env') }); |
10 | 21 |
|
11 | | -/** |
12 | | - * See https://playwright.dev/docs/test-configuration. |
13 | | - */ |
| 22 | +import { defineConfig, devices } from '@playwright/test'; |
| 23 | +import { APP_URLS, TIMEOUTS, VIEWPORTS } from './Tests/AngularNetTutorial-Playwright/config/test-config'; |
| 24 | + |
14 | 25 | export default defineConfig({ |
15 | | - testDir: './e2e', |
16 | | - /* Run tests in files in parallel */ |
| 26 | + /* Point at the submodule's test folder */ |
| 27 | + testDir: './Tests/AngularNetTutorial-Playwright/tests', |
| 28 | + |
| 29 | + timeout: TIMEOUTS.standard, |
| 30 | + expect: { |
| 31 | + timeout: TIMEOUTS.short, |
| 32 | + }, |
| 33 | + |
17 | 34 | fullyParallel: true, |
18 | | - /* Fail the build on CI if you accidentally left test.only in the source code. */ |
19 | 35 | forbidOnly: !!process.env.CI, |
20 | | - /* Retry on CI only */ |
21 | 36 | retries: process.env.CI ? 2 : 0, |
22 | | - /* Opt out of parallel tests on CI. */ |
23 | 37 | workers: process.env.CI ? 1 : undefined, |
24 | | - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ |
25 | | - reporter: 'html', |
26 | | - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ |
27 | | - use: { |
28 | | - /* Base URL to use in actions like `await page.goto('')`. */ |
29 | | - // baseURL: 'http://localhost:3000', |
30 | 38 |
|
31 | | - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ |
| 39 | + reporter: [ |
| 40 | + ['html', { outputFolder: 'Tests/AngularNetTutorial-Playwright/playwright-report', open: 'never' }], |
| 41 | + ['json', { outputFile: 'Tests/AngularNetTutorial-Playwright/test-results/results.json' }], |
| 42 | + ['junit', { outputFile: 'Tests/AngularNetTutorial-Playwright/test-results/junit.xml' }], |
| 43 | + ['list'], |
| 44 | + ], |
| 45 | + |
| 46 | + use: { |
| 47 | + baseURL: APP_URLS.angular, |
32 | 48 | trace: 'on-first-retry', |
| 49 | + video: 'retain-on-failure', |
| 50 | + screenshot: 'only-on-failure', |
| 51 | + viewport: VIEWPORTS.laptop, |
| 52 | + ignoreHTTPSErrors: true, |
| 53 | + actionTimeout: 10000, |
33 | 54 | }, |
34 | 55 |
|
35 | | - /* Configure projects for major browsers */ |
36 | 56 | projects: [ |
| 57 | + { |
| 58 | + name: 'setup', |
| 59 | + testMatch: /.*\.setup\.ts/, |
| 60 | + }, |
| 61 | + |
| 62 | + // Smoke Tests — critical path only (used in CI) |
| 63 | + { |
| 64 | + name: 'smoke', |
| 65 | + testMatch: /.*smoke\.spec\.ts/, |
| 66 | + use: { |
| 67 | + ...devices['Desktop Chrome'], |
| 68 | + viewport: VIEWPORTS.laptop, |
| 69 | + }, |
| 70 | + dependencies: ['setup'], |
| 71 | + }, |
| 72 | + |
| 73 | + // E2E Browser Tests |
37 | 74 | { |
38 | 75 | name: 'chromium', |
39 | | - use: { ...devices['Desktop Chrome'] }, |
| 76 | + use: { |
| 77 | + ...devices['Desktop Chrome'], |
| 78 | + viewport: VIEWPORTS.laptop, |
| 79 | + launchOptions: { |
| 80 | + args: ['--enable-precise-memory-info', '--disable-animations'], |
| 81 | + }, |
| 82 | + }, |
| 83 | + dependencies: ['setup'], |
40 | 84 | }, |
41 | 85 |
|
42 | 86 | { |
43 | 87 | name: 'firefox', |
44 | | - use: { ...devices['Desktop Firefox'] }, |
| 88 | + use: { |
| 89 | + ...devices['Desktop Firefox'], |
| 90 | + viewport: VIEWPORTS.laptop, |
| 91 | + }, |
| 92 | + dependencies: ['setup'], |
45 | 93 | }, |
46 | 94 |
|
47 | 95 | { |
48 | 96 | name: 'webkit', |
49 | | - use: { ...devices['Desktop Safari'] }, |
| 97 | + use: { |
| 98 | + ...devices['Desktop Safari'], |
| 99 | + viewport: VIEWPORTS.laptop, |
| 100 | + }, |
| 101 | + dependencies: ['setup'], |
50 | 102 | }, |
51 | 103 |
|
52 | | - /* Test against mobile viewports. */ |
53 | | - // { |
54 | | - // name: 'Mobile Chrome', |
55 | | - // use: { ...devices['Pixel 5'] }, |
56 | | - // }, |
57 | | - // { |
58 | | - // name: 'Mobile Safari', |
59 | | - // use: { ...devices['iPhone 12'] }, |
60 | | - // }, |
| 104 | + // API Integration Tests |
| 105 | + { |
| 106 | + name: 'api', |
| 107 | + testMatch: /Tests\/AngularNetTutorial-Playwright\/tests\/api\/.*\.spec\.ts/, |
| 108 | + testIgnore: [ |
| 109 | + /tests\/api\/auth-api\.spec\.ts/, |
| 110 | + /tests\/api\/cache-api\.spec\.ts/, |
| 111 | + /tests\/api\/departments-api\.spec\.ts/, |
| 112 | + /tests\/api\/employees-api\.spec\.ts/, |
| 113 | + ], |
| 114 | + use: { |
| 115 | + baseURL: APP_URLS.api, |
| 116 | + extraHTTPHeaders: { Accept: 'application/json' }, |
| 117 | + }, |
| 118 | + }, |
61 | 119 |
|
62 | | - /* Test against branded browsers. */ |
63 | | - // { |
64 | | - // name: 'Microsoft Edge', |
65 | | - // use: { ...devices['Desktop Edge'], channel: 'msedge' }, |
66 | | - // }, |
67 | | - // { |
68 | | - // name: 'Google Chrome', |
69 | | - // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, |
70 | | - // }, |
| 120 | + // Blog Screenshots — captures key UI states for blog posts and documentation |
| 121 | + { |
| 122 | + name: 'screenshots', |
| 123 | + testMatch: /Tests\/AngularNetTutorial-Playwright\/tests\/screenshots\/.*\.spec\.ts/, |
| 124 | + use: { |
| 125 | + ...devices['Desktop Chrome'], |
| 126 | + viewport: VIEWPORTS.laptop, |
| 127 | + video: 'off', |
| 128 | + screenshot: 'off', |
| 129 | + launchOptions: { |
| 130 | + slowMo: 150, |
| 131 | + }, |
| 132 | + }, |
| 133 | + }, |
71 | 134 | ], |
72 | | - |
73 | | - /* Run your local dev server before starting the tests */ |
74 | | - // webServer: { |
75 | | - // command: 'npm run start', |
76 | | - // url: 'http://localhost:3000', |
77 | | - // reuseExistingServer: !process.env.CI, |
78 | | - // }, |
79 | 135 | }); |
0 commit comments