Nightwatch adapter for WebdriverIO DevTools - brings the same visual debugging UI to your Nightwatch test suite with zero test code changes.
npm install @wdio/nightwatch-devtools1. Install the package in your Nightwatch project:
npm install @wdio/nightwatch-devtoolsRequires Nightwatch 3 or later. For Cucumber, @cucumber/cucumber must be installed in your project; the plugin uses your copy rather than bundling one.
2. Wire the plugin into your Nightwatch config via the globals field:
// nightwatch.conf.cjs
const nightwatchDevtools = require('@wdio/nightwatch-devtools').default
module.exports = {
src_folders: ['tests'],
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome',
// Required for network request capture
'goog:loggingPrefs': { performance: 'ALL' }
},
globals: nightwatchDevtools({ port: 3000 })
}
}
}3. Run your tests as normal — the DevTools UI opens automatically in a new browser window:
nightwatchNo changes to your test files are needed.
// nightwatch.conf.cjs
const nightwatchDevtools = require('@wdio/nightwatch-devtools').default
module.exports = {
src_folders: ['tests'],
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome',
// Required for network request capture
'goog:loggingPrefs': { performance: 'ALL' }
},
globals: nightwatchDevtools({ port: 3000 })
}
}
}Run your tests as normal — the DevTools UI opens automatically in a new browser window:
nightwatchNo changes to your test files are needed.
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.
// nightwatch.conf.cjs
const nightwatchDevtools = require('@wdio/nightwatch-devtools').default
const { cucumberHooksPath } = require('@wdio/nightwatch-devtools')
module.exports = {
src_folders: ['features/step_definitions'],
test_runner: {
type: 'cucumber',
options: {
feature_path: 'features',
require: [cucumberHooksPath] // <-- register DevTools Cucumber hooks
}
},
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome',
'goog:loggingPrefs': { performance: 'ALL' }
},
globals: nightwatchDevtools({ port: 3000 })
}
}
}Options are passed to the plugin through the globals field — globals: nightwatchDevtools({ ... }). All options are optional; the plugin runs fine with nightwatchDevtools({}). See Reference for the full option table.
globals: nightwatchDevtools({
port: 3000,
hostname: 'localhost',
screencast: { enabled: true }
})In the default mode: 'live', the plugin launches the DevTools dashboard in a new browser window when your tests run, streaming each test's commands, screenshots, console logs, and network activity in real time. The run stays open after your tests finish so you can review the results: close the DevTools window to end it, or press Ctrl+C to exit and leave the window open. See the dashboard docs for a walkthrough of the UI.
Available for Nightwatch — same dashboard UI as WebdriverIO. The "compare with rerun" flow snapshots the failing run, re-launches the test with DEVTOOLS_RERUN_LABEL set (the plugin filters down to just that test name on the rerun), and the dashboard shows the two runs side-by-side aligned by command.
Set mode: 'trace' to skip the DevTools UI window and instead write a portable, self-contained trace artifact at run end — for offline replay, CI artifact collection, or AI-agent diffing. The backend port-bind, the UI window, and the live-only screencast option are all skipped in trace mode.
globals: nightwatchDevtools({
mode: 'trace',
traceFormat: 'ndjson-directory' // optional; default 'zip'
})Nightwatch emits the same normalized trace as the WebdriverIO and Selenium adapters (all three share @wdio/devtools-trace), so the archive format and the show-trace player are identical no matter which adapter produced it. A Nightwatch trace carries the full per-action capture — a screenshot, the depth-indented accessibility-tree snapshot, the interactable-element list, and the Markdown transcript — so it opens in the player with DOM/snapshot time-travel, the A11y and Transcript tabs, an Errors tab surfacing expect/step failures with jump-to-source, the pick-locator element overlay, and (for Cucumber) Feature → Scenario nesting. Steps are tracked in the live dashboard but not yet nested as their own groups in the trace. Copied locators prefer plain CSS, which Nightwatch reads by default, and fall back to XPath (captioned useXpath() / locateStrategy: 'xpath') only when no unique CSS selector exists.
Open a trace with the show-trace bin, shipped with this package (no extra dependency):
npx show-trace test-results/trace-<sessionId>.zip # in a project that installs this adapter
pnpm show-trace test-results/trace-<sessionId>.zip # from the devtools monorepoFor the full artifact contents, the traceGranularity / tracePolicy reference, and the player walkthrough, see Trace mode and Viewing traces in the root README, and the Trace Mode docs.
The per-test options — traceGranularity: 'test', and the tracePolicy, screenshot, and video options that pair with it — need a per-test hook to cut each test's slice. The exports-object (mocha-style) interface and Cucumber (per-scenario hooks) expose one, so they get real per-test slicing. The BDD describe/it interface — the style used by this package's bundled example — is the exception: Nightwatch runs each it() internally and fires the plugin's per-test hook only once per module, so traceGranularity: 'test' collapses to a single session-scoped slice keyed to the first test. The artifacts manifest still lists every testcase with its correct state; only the per-test slice/artifact keying collapses. Session- and spec-granularity traces are unaffected.
Cucumber and traceGranularity. Nightwatch quits the browser after every scenario. A 'session' trace now spans that — one zip covering the whole run, every scenario, with each scenario nested under its feature. (Before, it captured only the last scenario, silently.) 'test' remains the recommendation for Cucumber: one zip per scenario, in its own folder, keyed for retention and smaller to open.
Enable WebDriver BiDi capture for browser console messages, JS exceptions, and network requests. Equivalent to the path selenium-devtools uses — both adapters call the same attachBidiHandlers in @wdio/devtools-core.
globals: nightwatchDevtools({
port: 3000,
bidi: true
})You also need webSocketUrl: true in your capabilities so chromedriver actually exposes the BiDi channel:
desiredCapabilities: {
browserName: 'chrome',
'webSocketUrl': true, // ← enables BiDi
'goog:chromeOptions': { /* ... */ }
}When attached, the per-command Chrome performance-log network capture path is gated off so requests don't appear twice in the dashboard. If webSocketUrl is missing or the chromedriver version doesn't expose BiDi, the attach logs a warning and the perf-log fallback continues to work. The injected collector lists every request as well, from two sources of the page's own: a fetch / XMLHttpRequest call goes through its patch and carries method, headers, status and body, and every other load comes from the page's Resource Timing buffer with its timing and size. On Chrome the performance log then upgrades those Resource Timing rows in place with headers and status; on Safari, or any session Appium serves, they stay as the page saw them, without headers or bodies, and on Safari without a status.
Set webSocketUrl: true even without bidi: true. With it, the plugin registers its page collector at document start on every page, so DOM time-travel stays accurate across navigations. Without it, the collector is injected after each navigation instead, which can miss the first moments of a new page.
Some reads the plugin makes go straight to the driver over the WebDriver HTTP transport instead of through Nightwatch's command queue: the page collector's probes and drains, the per-action snapshot probes and screenshots, the screencast's screenshots, and, on a session without BiDi, Chrome's performance log. A command issued through the queue while a test command is running would become part of that command and let its await return before it finished, so these reads never join the queue and never cut a test command short.
They use the connection Nightwatch itself is configured with: https when webdriver.ssl is set, or when it is unset and the port is 443, and basic authentication from webdriver.username and webdriver.access_key. A remote grid on https or behind credentials therefore needs no extra configuration for the plugin.
Record a continuous .webm video of the browser session, live mode only (in trace mode use filmstrip / video). Each WebDriver session gets its own recording: a mid-run browser.end(), or the per-scenario browser quit in Cucumber, finalizes the current video and starts a new one. The last recording is finalized in Nightwatch's after() hook. Each is written as nightwatch-video-<sessionId>.webm to a test-results/ folder next to the test file that just ran, falling back to the directory containing nightwatch.conf.*, then process.cwd(). Directories under node_modules/ are skipped, and an unwritable directory falls back to the OS temp directory.
Polling mode only. Nightwatch doesn't expose a stable CDP escape hatch the way WebdriverIO (browser.getPuppeteer()) and Selenium (driver.createCDPConnection) do, so the screencast captures frames by requesting a WebDriver screenshot at a fixed interval, straight over the WebDriver HTTP transport so it never waits behind your test's queued commands. This works on every browser Nightwatch supports.
globals: nightwatchDevtools({
port: 3000,
screencast: { enabled: true, pollIntervalMs: 200 }
})| Option | Type | Default | Notes |
|---|---|---|---|
enabled |
boolean |
false |
Master switch. |
pollIntervalMs |
number |
200 |
Screenshot interval (ms). Lower = smoother video, more WebDriver round-trips. 200 ms ≈ 5 fps. |
captureFormat |
'jpeg' | 'png' |
'jpeg' |
Frame format. WebDriver screenshots are always PNG, so this only affects the encoded output. |
maxBufferFrames |
number |
2000 |
Cap on frames held in memory; past it the buffer is thinned in place, keeping the first and last frames. |
maxWidth / maxHeight / quality |
— | — | CDP-only options, ignored in polling mode. Listed for shape compatibility with the WDIO/Selenium adapters. |
fluent-ffmpeg (already a runtime dep of this package) plus the ffmpeg binary on PATH. macOS: brew install ffmpeg. Linux: apt install ffmpeg. Without ffmpeg the recorder still runs but the encode step logs a warning and skips writing the file.
The encoded video is sent to the DevTools dashboard via the screencast WS scope and shown in the Screencast tab. The absolute path also appears in the Nightwatch log line 📹 Screencast video: <path>.
| Option | Type | Default | Description |
|---|---|---|---|
port |
number |
3000 |
Port for the DevTools backend server. Auto-incremented if already in use. |
hostname |
string |
'localhost' |
Hostname the backend server binds to. |
screencast |
ScreencastOptions |
{ enabled: false } |
Session video recording — live mode only (see Screencast). |
bidi |
boolean |
false |
Opt into WebDriver BiDi capture for browser console + JS exceptions + network. Requires webSocketUrl: true in your capabilities and a BiDi-capable chromedriver. When attached, the per-command Chrome perf-log network path is gated off so requests don't duplicate. |
mode |
'live' | 'trace' |
'live' |
'live' opens the DevTools UI window; 'trace' skips the UI and writes a trace-<sessionId>.zip (or directory) under a test-results/ directory at run end (base dir resolved from the test file dir → config dir → cwd). See Trace mode. |
traceFormat |
'zip' | 'ndjson-directory' |
'zip' |
Trace artifact layout — zip writes a single archive, ndjson-directory unpacks the same files into trace-<sessionId>/. Only applies when mode: 'trace'. |
traceGranularity |
'session' | 'spec' | 'test' |
'session' |
One trace per session / spec file / test. 'test' is what the per-test screenshot / video artifacts attach to. Only applies when mode: 'trace'. Caveat: the BDD describe/it interface collapses to a single session-scoped slice (see Per-test slicing). For Cucumber, 'session' spans every scenario in one zip; 'test' gives one per scenario and is the recommendation. |
tracePolicy |
'on' | 'retain-on-failure' | 'retain-on-first-failure' | 'on-first-retry' | 'on-all-retries' | 'retain-on-failure-and-retries' |
'on' |
Which traces to keep. Pairs with traceGranularity: 'test'. Only applies when mode: 'trace'. |
filmstrip |
boolean |
true |
Record a dense, continuous screencast filmstrip into the trace for scrubbable playback in the trace player, not just one frame per action. Runs the screencast recorder (polling mode on Nightwatch) for the session. The polling recorder skips a tick while a command or a per-action capture holds the driver (once the newest frame is three intervals old it polls anyway, so the longest gap is about three intervals plus one screenshot; never during a click, typing or a capture), and keeps each per-action capture's screenshot as a frame, so its polls do not queue in front of the test. Only applies when mode: 'trace'. |
traceResources |
'styles' | 'none' |
'styles' |
Trace mode only. 'styles' stores the stylesheets and fonts each archive's pages used, once each by content hash, so the player replays them from the archive rather than the site; 'none' stores nothing. Images always replay from the site. See the root README for caps and how the reads are kept out of the network rows. |
screenshot |
'off' | 'on' | 'only-on-failure' |
'off' |
Per-test screenshot. Trace mode + traceGranularity: 'test' only. Produce-only — the PNG is written to the trace output dir (and listed in the artifacts manifest when emitArtifactsManifest: true); it is NOT attached inline to Allure (see note below). |
video |
'off' | TraceRetentionPolicy |
'off' |
Per-test video slice, retained per the given policy (e.g. 'retain-on-failure'). Trace mode + traceGranularity: 'test' only. Setting a non-off policy starts the screencast recorder itself — you do not also need filmstrip or screencast.enabled; the recorder runs continuously for the session and each test's slice is cut from it by wall-clock window. Produce-only — the .webm is written to the trace output dir (and listed in the manifest when emitArtifactsManifest: true); NOT attached inline to Allure. |
emitArtifactsManifest |
boolean |
false |
Write the devtools-artifacts-<sessionId>.json manifest — the generic index reporters/CI consume to discover produced artifacts — next to the trace. Opt-in for Nightwatch: it has no live Allure signal to auto-detect against (nightwatch-allure is post-hoc), so unlike WDIO/Selenium it never auto-enables. Trace mode only. |
captureAssertions |
boolean |
true |
Capture assertions as trace action rows — node:assert plus native browser.assert.* / browser.verify.*, including negated .not.* matchers. Passing assertions render green, failing ones red with the error. Set false to opt out. |
maskInputs |
boolean |
true |
Replace the value of password fields with •••• in the replayed page (DOM anchor, field state, value mutations), and redact what was typed into them, and the values of Authorization, Proxy-Authorization, Cookie and Set-Cookie headers, from command rows, network, console and the trace, live and trace mode alike. false turns both off. See Password masking and Secret redaction. |
maskSelectors |
string[] |
[] |
Also mask the text and value of every element these CSS selectors match, and everything inside it, in the replayed page. |
secrets |
Array<string | { env: string }> |
[] |
Values replaced by •••• in everything the dashboard and the trace receive, on top of the typed passwords maskInputs redacts: command rows, console, network, DOM, sources. { env: 'NAME' } reads the value from that variable at start; a value under 4 characters is ignored with a warning. See Secret redaction. |
Before a typing command (setValue, setPassword, sendKeys, updateValue) whose value is 4 characters or more, the plugin queues one perform that reads the field's type, so a typed password is redacted from its own row on. That perform may appear in Nightwatch's own reporter output, once per password typed.
Inline Allure attachment is not supported for Nightwatch. Its official
nightwatch-allurereporter is post-hoc (no live attach API), andallure-js-commons'attachment()no-ops in a Nightwatch run. Soscreenshot/videoartifacts are produced (files, plus the artifacts manifest whenemitArtifactsManifest: true) in the trace output dir but not attached to an Allure test. Per-test slicing (and therefore these artifacts) is meaningful for the cucumber and exports-object interfaces; the BDDdescribe/itinterface collapses to session granularity, so the gate no-ops there.
Appium sessions are captured in live and trace mode. Declare Appium under selenium with use_appium: true, start_process: false and default_path_prefix: ''. For a native app set browserName: null; otherwise Nightwatch fills in Firefox and the plugin treats the session as having a web page. Leave bidi off, since Appium serves no BiDi.
// nightwatch.mobile.conf.cjs
const nightwatchDevtools = require('@wdio/nightwatch-devtools').default
module.exports = {
selenium: {
start_process: false,
use_appium: true,
host: '127.0.0.1',
port: 4723,
default_path_prefix: ''
},
test_settings: {
default: {
desiredCapabilities: {
browserName: null,
platformName: 'Android',
'appium:automationName': 'UiAutomator2'
},
globals: nightwatchDevtools({ mode: 'trace', bidi: false })
}
}
}Native sessions record commands, screenshots and element data from the platform's XML tree, with no DOM: in trace mode each action's element list and accessibility tree are built from the app's page source, read beside its screenshot, which on iOS is most of the capture's cost. A hybrid app's webview is captured as if it were still native. From the root of a built checkout of this repo (pnpm install && pnpm build), try it with pnpm demo:nightwatch:mobile; prerequisites are in examples/MOBILE.md, and the full reference is the Mobile Testing page.
A native app has no document and Appium serves no BiDi network events, so by default the Network tab of a native session is empty. The plugin can read the app's traffic from the appium-interceptor plugin instead, which routes the device through a proxy of its own:
appium plugin install --source=npm appium-interceptor
appium --use-plugins=appium-interceptorThen ask for the proxy in desiredCapabilities:
desiredCapabilities: {
browserName: null,
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:app': '/path/to/app.apk',
'appium:intercept': true
}The plugin starts a listener for each session, including one that replaces it mid-run, and reads what the proxy recorded at most every 2 seconds between commands (each read returns the whole history), and always before each test's trace slice is written, in both live and trace mode. Each request shows its method, URL, status, headers and bodies. The plugin records no timing, so a request is placed at the moment it was first read and shows no duration. Without the plugin a warning is logged and the session runs as usual. This applies to native sessions only; a mobile browser session already captures its network through the page.
The plugin supports Android. For HTTPS traffic the app has to trust the certificate the plugin installs on the device, which a release build usually does not (see Android's network security configuration).
Working examples live in the repo's top-level examples/nightwatch/. Build the workspace once (pnpm install && pnpm build), then run from the repo root:
| Example | Runner | Command |
|---|---|---|
examples/nightwatch/ |
Nightwatch BDD describe/it (trace mode by default; DEVTOOLS_MODE=live for the UI) |
pnpm demo:nightwatch (pnpm demo:nightwatch:retry adds --retries 1) |
examples/nightwatch/cucumber/ |
Nightwatch + Cucumber | pnpm --filter @wdio/nightwatch-devtools example:cucumber |
examples/nightwatch/nightwatch.mobile.conf.cjs |
Appium (Android Clock app; iOS Settings with DEVTOOLS_MOBILE_PLATFORM=ios) |
pnpm demo:nightwatch:mobile |
Nightwatch does not provide the same depth of framework hooks as WebdriverIO, so there are a few differences from the WDIO DevTools service:
| Limitation | Detail |
|---|---|
| No native command hooks | Nightwatch has no beforeCommand / afterCommand hook. Commands are intercepted via a browser proxy wrapper instead. |
| Limited test context | browser.currentTest provides less metadata than the WDIO runner context; test names and file paths require additional heuristics. |
| Flat suite nesting | Nightwatch does not natively support multiply-nested describe blocks; the plugin reports a maximum of two levels. |
| Delayed result availability | Test results are only finalised in afterEach, not available mid-test. |
Per-test trace slicing (BDD describe/it) |
The BDD interface fires the plugin's per-test hook once per module, so traceGranularity: 'test' collapses to one session-scoped slice. The exports-object (mocha-style) and Cucumber interfaces get real per-test slicing. See Per-test slicing. |
| Element waits show no polls | A waitForElement* wait is one row with nothing nested under it: Nightwatch polls for the element through its own transport, which the plugin does not see. A waitUntil row nests the commands its condition issued. See Waits. |
| A wait that never ran is a failed row | Nightwatch queues every command up front, so a wait queued behind a failing assert never runs. Its row is closed at the end of the test as failed, "did not run", rather than left looking like it passed. |
| Produce-only trace artifacts | Per-test screenshot / video files are written to the trace output dir (and the manifest when emitArtifactsManifest: true) but not attached inline to Allure — Nightwatch has no live Allure attach API. |
Overall feature parity with the WebdriverIO DevTools service is approximately 80–90%.