|
1 | 1 | # @wdio/nightwatch-devtools |
2 | 2 |
|
3 | | -> Nightwatch adapter for WebdriverIO DevTools - Visual debugging UI for your Nightwatch tests |
4 | | -
|
5 | | -## What is this? |
6 | | - |
7 | | -Brings the powerful WebdriverIO DevTools visual debugging interface to Nightwatch tests with **zero test code changes**. |
8 | | - |
9 | | -See everything in real-time: |
10 | | -- 📋 **Commands** - Every action executed |
11 | | -- 🖥️ **Console** - Browser console logs |
12 | | -- 🌐 **Network** - HTTP requests/responses |
13 | | -- ✅ **Tests** - Suite structure and results |
14 | | -- 📁 **Sources** - Test file contents |
15 | | -- 📝 **Logs** - Framework debugging |
| 3 | +> Nightwatch adapter for [WebdriverIO DevTools](../../README.md) - brings the same visual debugging UI to your Nightwatch test suite with zero test code changes. |
16 | 4 |
|
17 | 5 | ## Installation |
18 | 6 |
|
19 | 7 | ```bash |
20 | | -npm install @wdio/nightwatch-devtools --save-dev |
| 8 | +npm install --save-dev @wdio/nightwatch-devtools |
21 | 9 | # or |
22 | 10 | pnpm add -D @wdio/nightwatch-devtools |
23 | 11 | ``` |
24 | 12 |
|
25 | | -## Usage |
| 13 | +--- |
| 14 | + |
| 15 | +## Setup |
26 | 16 |
|
27 | | -Add to your Nightwatch config: |
| 17 | +### Standard Nightwatch (mocha-style) |
28 | 18 |
|
29 | 19 | ```javascript |
30 | | -// nightwatch.conf.js |
31 | | -const nightwatchDevtools = require('@wdio/nightwatch-devtools').default; |
| 20 | +// nightwatch.conf.cjs |
| 21 | +const nightwatchDevtools = require('@wdio/nightwatch-devtools').default |
32 | 22 |
|
33 | 23 | module.exports = { |
34 | 24 | src_folders: ['tests'], |
35 | 25 |
|
36 | 26 | test_settings: { |
37 | 27 | default: { |
38 | 28 | desiredCapabilities: { |
39 | | - browserName: 'chrome' |
| 29 | + browserName: 'chrome', |
| 30 | + // Required for network request capture |
| 31 | + 'goog:loggingPrefs': { performance: 'ALL' } |
40 | 32 | }, |
41 | | - // Add DevTools globals with lifecycle hooks |
42 | | - globals: nightwatchDevtools() |
| 33 | + globals: nightwatchDevtools({ port: 3000 }) |
43 | 34 | } |
44 | 35 | } |
45 | 36 | } |
46 | 37 | ``` |
47 | 38 |
|
48 | | -Run your tests: |
| 39 | +Run your tests as normal — the DevTools UI opens automatically in a new browser window: |
49 | 40 |
|
50 | 41 | ```bash |
51 | 42 | nightwatch |
52 | 43 | ``` |
53 | 44 |
|
54 | | -The DevTools UI will automatically: |
55 | | -1. Start backend server on port 3000 |
56 | | -2. Open in a new browser window |
57 | | -3. Stream test data in real-time |
58 | | -4. Stay open after tests finish (close manually to exit) |
59 | | - |
60 | | -## Example |
61 | | - |
62 | | -See [`example/`](./example) directory for a working sample with: |
63 | | -- Sample test suite |
64 | | -- Nightwatch configuration |
65 | | -- Setup instructions |
66 | | - |
67 | | -Run it: |
68 | | -```bash |
69 | | -cd packages/nightwatch-devtools |
70 | | -pnpm build |
71 | | -pnpm example # Run tests with DevTools UI |
72 | | -``` |
73 | | - |
74 | | -## How It Works |
75 | | - |
76 | | -This is a **thin adapter** (~210 lines) that: |
| 45 | +> No changes to your test files are needed. |
77 | 46 |
|
78 | | -1. ✅ Reuses `@wdio/devtools-backend` - Fastify server + WebSocket |
79 | | -2. ✅ Reuses `@wdio/devtools-app` - Lit-based UI components |
80 | | -3. ✅ Reuses `@wdio/devtools-script` - Browser capture |
81 | | -4. ✅ Adds only Nightwatch lifecycle hooks: `before`, `beforeSuite`, `beforeEach`, `afterEach`, `after` |
| 47 | +--- |
82 | 48 |
|
83 | | -Same backend, same UI, same capture as WDIO - just different framework hooks! |
| 49 | +### Cucumber / BDD |
84 | 50 |
|
85 | | -## Options |
| 51 | +Import `cucumberHooksPath` alongside the main export and pass it to the Cucumber `require` option. This registers `Before` / `After` scenario hooks that mirror the WebdriverIO service's `beforeScenario` / `afterScenario` behaviour. |
86 | 52 |
|
87 | 53 | ```javascript |
88 | | -const nightwatchDevtools = require('@wdio/nightwatch-devtools').default; |
| 54 | +// nightwatch.conf.cjs |
| 55 | +const nightwatchDevtools = require('@wdio/nightwatch-devtools').default |
| 56 | +const { cucumberHooksPath } = require('@wdio/nightwatch-devtools') |
89 | 57 |
|
90 | 58 | module.exports = { |
| 59 | + src_folders: ['features/step_definitions'], |
| 60 | + |
| 61 | + test_runner: { |
| 62 | + type: 'cucumber', |
| 63 | + options: { |
| 64 | + feature_path: 'features', |
| 65 | + require: [cucumberHooksPath] // <-- register DevTools Cucumber hooks |
| 66 | + } |
| 67 | + }, |
| 68 | + |
91 | 69 | test_settings: { |
92 | 70 | default: { |
93 | | - globals: nightwatchDevtools({ |
94 | | - port: 3000, // DevTools server port (default: 3000) |
95 | | - hostname: 'localhost' // DevTools server hostname (default: 'localhost') |
96 | | - }) |
| 71 | + desiredCapabilities: { |
| 72 | + browserName: 'chrome', |
| 73 | + 'goog:loggingPrefs': { performance: 'ALL' } |
| 74 | + }, |
| 75 | + globals: nightwatchDevtools({ port: 3000 }) |
97 | 76 | } |
98 | 77 | } |
99 | 78 | } |
100 | 79 | ``` |
101 | 80 |
|
102 | | -## What Gets Captured |
| 81 | +--- |
| 82 | + |
| 83 | +## Configuration Options |
| 84 | + |
| 85 | +| Option | Type | Default | Description | |
| 86 | +|--------|------|---------|-------------| |
| 87 | +| `port` | `number` | `3000` | Port for the DevTools backend server. Auto-incremented if already in use. | |
| 88 | +| `hostname` | `string` | `'localhost'` | Hostname the backend server binds to. | |
| 89 | + |
| 90 | +```javascript |
| 91 | +globals: nightwatchDevtools({ |
| 92 | + port: 3000, |
| 93 | + hostname: 'localhost' |
| 94 | +}) |
| 95 | +``` |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Examples |
| 100 | + |
| 101 | +Working examples are included in this package: |
| 102 | + |
| 103 | +| Directory | Runner | Command | |
| 104 | +|-----------|--------|---------| |
| 105 | +| [`example/`](./example) | Nightwatch mocha-style | `pnpm example` | |
| 106 | + |
| 107 | +Build the package first: |
| 108 | + |
| 109 | +```bash |
| 110 | +# From repo root |
| 111 | +pnpm build --filter @wdio/nightwatch-devtools |
| 112 | +cd packages/nightwatch-devtools |
| 113 | +pnpm example |
| 114 | +``` |
| 115 | + |
| 116 | +--- |
103 | 117 |
|
104 | | -✅ Test suites and hierarchy |
105 | | -✅ Test pass/fail status |
106 | | -✅ Execution timing |
107 | | -✅ Error messages and stack traces |
108 | | -✅ Browser console logs (automatic) |
109 | | -✅ Network requests (automatic) |
110 | | -✅ DOM mutations (automatic) |
| 118 | +## Limitations |
111 | 119 |
|
112 | | -Browser-side capture works automatically via `@wdio/devtools-script`. |
| 120 | +Nightwatch does not provide the same depth of framework hooks as WebdriverIO, so there are a few differences from the WDIO DevTools service: |
113 | 121 |
|
114 | | -## Requirements |
| 122 | +| Limitation | Detail | |
| 123 | +|-----------|--------| |
| 124 | +| No native command hooks | Nightwatch has no `beforeCommand` / `afterCommand` hook. Commands are intercepted via a browser proxy wrapper instead. | |
| 125 | +| Limited test context | `browser.currentTest` provides less metadata than the WDIO runner context; test names and file paths require additional heuristics. | |
| 126 | +| Flat suite nesting | Nightwatch does not natively support multiply-nested `describe` blocks; the plugin reports a maximum of two levels. | |
| 127 | +| Delayed result availability | Test results are only finalised in `afterEach`, not available mid-test. | |
115 | 128 |
|
116 | | -- **Nightwatch**: >= 3.0.0 |
117 | | -- **Node.js**: >= 18.0.0 |
118 | | -- **Chrome/Chromium**: For tests and UI |
| 129 | +Overall feature parity with the WebdriverIO DevTools service is approximately **80–90%**. |
119 | 130 |
|
120 | | -## License |
| 131 | +## :page_facing_up: License |
121 | 132 |
|
122 | | -MIT |
| 133 | +[MIT](/LICENSE) |
0 commit comments