Debug WebdriverIO Tests
A failing WebdriverIO test tells you which command or assertion broke, but not what the page looked like, which request failed or what the browser console said at that moment. WebdriverIO DevTools records all of that for every command. Use live mode to watch a failing test, inspect each step and rerun it on your machine, and trace mode to keep a replayable file of every failure in CI. It works with Mocha, Jasmine and Cucumber, in desktop and mobile browsers and in Appium apps. A native app has no page or browser console, so there DevTools records each step's screenshot and element tree instead; see Mobile Testing.
Set up DevTools​
Install the service:
npm install @wdio/devtools-service --save-dev
Add it to your config:
export const config: WebdriverIO.Config = {
// ...
services: ['devtools'],
}
The service needs Node.js 22.23.4+, 24.22.1+ or 26.12.1+ and a browser session with WebDriver BiDi (Chrome 114+, Firefox 130+), which WebdriverIO enables automatically. All options are on the WebdriverIO DevTools page.
Debug a failing test on your machine​
Run the spec that fails:
npx wdio run wdio.conf.ts --spec test/specs/login.e2e.ts
The DevTools dashboard opens in a new browser window and fills in as the test runs. When the run ends:
- Select the failed test in the sidebar. The Actions list shows its commands in the order they ran, and the one that failed is marked.
- Select a command. The browser pane shows the page as it was after that command, so you can see whether the element you expected was there, hidden or covered.
- Use the bottom tabs to find the cause:
| You want to know | Look at |
|---|---|
| The error and the line that raised it | Errors, then Source to see the test code |
| What the selected command was called with and what it returned | Log |
| Whether an API call failed or returned something unexpected | Network, then select a request for its headers, status and timing |
| Whether the app logged an error or threw an exception | Console |
- Fix the test or the app, then click â–¶ on the test's row to rerun only that test. The rerun starts a fresh test process, so it runs your edited code, and streams into the same window.
To stop at a point in the test and try commands by hand instead, use browser.debug().
Debug a test that fails only in CI​
CI has no screen to open a dashboard on, so record a trace instead. Switch to trace mode only in CI, and keep only the tests that failed:
export const config: WebdriverIO.Config = {
// ...
services: [
['devtools', process.env.CI
? { mode: 'trace', traceGranularity: 'test', tracePolicy: 'retain-on-failure' }
: {}
]
]
}
At the end of each worker the service prints the path of every trace it kept:
DevTools trace saved to /path/to/project/test-results/login_e2e-logs-in-chrome/trace.zip
Traces are written to a test-results/ folder next to your WebdriverIO config, or inside your outputDir if you set one. A passing test writes nothing, so a green run leaves nothing to upload. Upload the folder as a build artifact. On GitHub Actions:
- name: Run tests
run: npx wdio run wdio.conf.ts
- name: Upload DevTools traces
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: devtools-traces
path: |
**/test-results/
!**/node_modules/**
if-no-files-found: ignore
To open the traces, download the artifact, unzip it and run:
npx show-trace test-results/
The trace player lists every test with its outcome, failures first. It has the same tabs as the dashboard, plus DOM time-travel, the A11y tab for copying a working selector and a scrubbable filmstrip of the run. To open a trace without installing anything, drop the folder on trace.webdriver.io; the file is read in your browser tab and uploaded nowhere.
Traces mask password fields and the Authorization, Cookie and Set-Cookie headers by default. Add the secrets option for other values, such as API tokens, before you share a trace.
Debug a flaky test​
A flaky test fails on one run and passes on the next. Compare the two runs rather than reading two logs side by side.
On your machine, hover the failed test's row and click the bug-and-play icon next to â–¶. Preserve & Rerun keeps the failed run, reruns the test, and opens the Compare tab with both runs aligned command by command. The first command where they differ is highlighted, along with the assertion's expected and received values.
In CI, retry failed tests once, and change the policy from the previous section so it also keeps every test that needed a retry:
export const config: WebdriverIO.Config = {
// ...
mochaOpts: {
retries: 1
},
services: [
['devtools', process.env.CI
? { mode: 'trace', traceGranularity: 'test', tracePolicy: 'retain-on-failure-and-retries' }
: {}
]
]
}
Each attempt writes its own folder, for example test-results/login_e2e-logs-in-chrome/trace.zip for the first attempt and test-results/login_e2e-logs-in-chrome-retry1/trace.zip for the retry, so you can open the failed attempt next to the one that passed. Retries set with specFileRetries run in a new worker and are not tracked as retries; use the framework's own retries (mochaOpts.retries or cucumberOpts.retry). The other policies are listed under Retention.
Hand a failure to a coding agent​
Every trace contains transcript.md, a Markdown summary of the test's commands with their selectors, values and errors. Point your agent at the failed test's folder and ask it to read transcript.md first, or click Copy on the player's Transcript tab to paste the transcript and the failing errors into a chat. Set traceFormat: 'ndjson-directory' to write the trace as plain files the agent can read without unzipping. AI Agents covers the rest of that setup.
Troubleshooting​
test-results/ is empty after a run that failed. Check that the job runs with CI set, so the config above picks trace mode, and look for the DevTools trace saved to line in the output. With tracePolicy: 'retain-on-failure', a test that failed and then passed on a retry counts as passed and is not kept; use 'retain-on-failure-and-retries' to keep it.
The Network tab is empty for a native app. A native app has no page to read requests from, and Appium serves no WebDriver BiDi. Capture the app's traffic with the appium-interceptor plugin, which works on Android with Appium 3, as described in Native app network. For Appium sessions, also set 'wdio:enforceWebDriverClassic': true in the capability block.
Next steps​
- Trace Mode: every trace option, including granularity, retention, screenshots and video.
- Trace Player: the player's tabs, keyboard shortcuts and shareable links.
- Mobile Testing: debug Appium tests on Android and iOS.
- Allure Integration: attach traces to an Allure report.
- Debugging:
browser.debug(), IDE breakpoints and profiling.