Skip to content

Commit 4b74283

Browse files
committed
Nightwatch devtools readme
1 parent 0ea4b3f commit 4b74283

File tree

1 file changed

+82
-71
lines changed

1 file changed

+82
-71
lines changed
Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,133 @@
11
# @wdio/nightwatch-devtools
22

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.
164
175
## Installation
186

197
```bash
20-
npm install @wdio/nightwatch-devtools --save-dev
8+
npm install --save-dev @wdio/nightwatch-devtools
219
# or
2210
pnpm add -D @wdio/nightwatch-devtools
2311
```
2412

25-
## Usage
13+
---
14+
15+
## Setup
2616

27-
Add to your Nightwatch config:
17+
### Standard Nightwatch (mocha-style)
2818

2919
```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
3222

3323
module.exports = {
3424
src_folders: ['tests'],
3525

3626
test_settings: {
3727
default: {
3828
desiredCapabilities: {
39-
browserName: 'chrome'
29+
browserName: 'chrome',
30+
// Required for network request capture
31+
'goog:loggingPrefs': { performance: 'ALL' }
4032
},
41-
// Add DevTools globals with lifecycle hooks
42-
globals: nightwatchDevtools()
33+
globals: nightwatchDevtools({ port: 3000 })
4334
}
4435
}
4536
}
4637
```
4738

48-
Run your tests:
39+
Run your tests as normal — the DevTools UI opens automatically in a new browser window:
4940

5041
```bash
5142
nightwatch
5243
```
5344

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.
7746
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+
---
8248

83-
Same backend, same UI, same capture as WDIO - just different framework hooks!
49+
### Cucumber / BDD
8450

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.
8652

8753
```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')
8957

9058
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+
9169
test_settings: {
9270
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 })
9776
}
9877
}
9978
}
10079
```
10180

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+
---
103117

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
111119

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:
113121

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. |
115128

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%**.
119130

120-
## License
131+
## :page_facing_up: License
121132

122-
MIT
133+
[MIT](/LICENSE)

0 commit comments

Comments
 (0)