-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
132 lines (115 loc) · 3.74 KB
/
playwright.config.ts
File metadata and controls
132 lines (115 loc) · 3.74 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { defineConfig, devices } from '@playwright/test';
import path from 'path';
/**
* Playwright configuration for QuickKee Chrome Extension E2E testing
*
* IMPORTANT: Before running E2E tests:
* 1. Build the extension: npm run build (or yarn build)
* 2. The extension will be loaded from ./dist folder
*
* Chrome extensions require:
* - Headed mode (headless: false) - extensions don't work in headless
* - Persistent context with userDataDir
* - Chrome launch args to load the extension
*
* To get the extension ID after loading:
* 1. Run a test that navigates to chrome://extensions
* 2. Find the extension ID in the list
* 3. Use chrome-extension://<ID>/src/popup/index.html to access the popup
*/
const extensionPath = path.resolve(__dirname, 'dist');
export default defineConfig({
testDir: './tests/e2e',
/* Maximum time one test can run for */
timeout: 30 * 1000,
/* Run tests in files in parallel */
fullyParallel: false, // Set to false for extension tests to avoid conflicts
/* Fail the build on CI if you accidentally left test.only in the source code */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI */
workers: 1, // Single worker for extension testing
/* Reporter to use */
reporter: [
['html', { open: 'never' }],
['list']
],
/* Shared settings for all the projects below */
use: {
/* Base URL for navigation - uses dev server */
baseURL: 'http://localhost:3457',
/* Collect trace when retrying the failed test */
trace: 'on-first-retry',
/* Screenshot on failure */
screenshot: 'only-on-failure',
},
/* Configure projects */
projects: [
{
name: 'chromium-extension',
testMatch: /(extension|cloud-storage)\.spec\.ts/,
use: {
/* Chrome channel for extension support */
channel: 'chrome',
/* Extensions require headed mode */
headless: false,
/* Launch options for Chrome with extension */
launchOptions: {
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`,
'--no-sandbox',
'--disable-setuid-sandbox',
],
},
},
},
{
name: 'dev-server',
testMatch: /dev-server\.spec\.ts/,
use: {
/* Use Chromium for dev server testing (no extension needed) */
...devices['Desktop Chrome'],
headless: true,
},
},
],
/* Run your local dev server before starting the tests */
webServer: {
command: 'node serve.js',
url: 'http://localhost:3457',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
},
});
/**
* Extension ID Retrieval Process:
*
* Chrome extension IDs are generated based on the extension's key or path.
* For local development, the ID is based on the absolute path of the extension.
*
* To find your extension ID:
*
* 1. Manual method:
* - Open Chrome with the extension loaded (run a Playwright test)
* - Navigate to chrome://extensions
* - Find "QuickKee" and copy the ID shown below the name
*
* 2. Programmatic method (in test):
* ```typescript
* // Navigate to service worker to get extension context
* const [background] = context.serviceWorkers();
* const extensionId = background.url().split('/')[2];
* ```
*
* 3. Using chrome.runtime in test:
* ```typescript
* const extensionId = await page.evaluate(() => chrome.runtime.id);
* ```
*
* Once you have the extension ID, access extension pages via:
* - Popup: chrome-extension://<ID>/src/popup/index.html
* - Side Panel: chrome-extension://<ID>/src/sidepanel/index.html
* - Settings: chrome-extension://<ID>/src/settings/index.html
*/